How do I maintain motivation in a completely awful grad program? I am a 2nd year PhD student.

I regret my choice of grad school severely. The program here has a good reputation and I have no idea how or why it has a good reputation. The program here is absolutely terrible. The location is terrible and depressing, classes are completely useless, the qual system is really terrible (I passed them, I still think the way they're done is awful), most of my cohort are petty and childish (although I've found a few very good people here who I'm super grateful for), I have no support basically. I have met many people in the department that feel the same way: ranging from other grad students to professors. 

This program is awful and coming here was one of the worst decisions of my life. I had other good programs I could have gone to.

I've found it much harder to read/do problems/etc. I barely do enough work just to pass classes. I try to focus on the stuff I want to do, but it seems like just by being here the subject is tainted.

Last night I found a problem online I tried working out but couldn't. I spent all day today - I barely ate, I didn't do anything else, I just worked all day long on this stupid problem that had nothing to do with anything. It was a blast! It reminded me of why I love my subject. I failed to find a solution...but it was still very productive and I learned a lot. I let myself get obsessed and I didn't worry about all the issues here.

How do I keep this feeling? How do I stay motivated? The department here feels like it saps all of my will to do any work out. In undergrad I was so determined. I took some time off between undergrad and grad and it only made me more determined. I want to feel like I did today.

I looked into transferring into other programs but it seemed like it would be a huge pain and I've been able to make it through the worst part of the program pretty quickly.
I think the first thing is to take a break - a week away from your department, in which you read no email and keep contact with no one there. From the text of the question, I understand you may be stressed and burnt out, so you do need the break. If you forget these breaks, burnout can become depression, which would complicate your life even further.

Other than that, try to hang out only with people who stress you the least, and if stressful people are in your office, work more from home, or switch offices. You didn't mention if you had an adviser, or not, but you said you had no support, so it could be an idea to go to an adviser with a less negative attitude, since you don't have a research assistantship to risk. 

Another option, is quitting the department for a better graduate school. I had a friend who did that for the same reasons you state, and the fact that he had passed the qualifying exam helped him get into the happier graduate program.

I also want to say that doing research isn't always a happy process. You may work for two years on a project and seem to get good results, but when you do your final check before publication, you realize you had an error in your work and, without it, your results are trivial and useless. That's just a part of life as a researcher that will always depress you.