Time, trust and patience. That's the secret, as everyone has mentioned. I took in a young cat that had been abandoned, and we all believe she was mistreated as well. Same scenario. One minute loving and cuddling, the next minute her ears were flat back, tail huge and claws out. Jokingly we nicknamed her 'Face Biter', because you could be holding her and suddenly she would growl and actually snap at your face. And those claws were wicked.
I left her to her own devices. Having other cats, she was never alone, but it seemed at night she wanted to sleep in our room. So we would let her. She'd stay at the foot of the bed, sometimes venturing up to sniff one of us. On rare ocassions she's snuggle close and go to sleep. We'd sometimes pet her, or scratch an ear. Always talked to her in a soft voice. This has become a nightly ritual.
Its been almost 9 months and Noelle (her real name) has mellowed out some. She's more content in her new surroundings. She comes when she is called. We can scoop her up and play with her, or scritch along her back when she comes along side us. When its bedtime, she will make her presence known ... nuzzle us and lick our cheeks or nose, then go take her place at the foot of the bed.
Time, trust and patience. She will come around.