-
Notifications
You must be signed in to change notification settings - Fork 1
/
Model.hs
49 lines (39 loc) · 1.67 KB
/
Model.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{-# LANGUAGE CPP #-}
-- | Generic class for handling different types of models.
module Model( Model (..)
, TorsionModel (..)
, initTorsionModel
, modifyTorsionModelM ) where
import Control.DeepSeq(NFData(..))
import Debug.Trace(traceShow) -- DEBUG
import Topo
#ifdef OLD_BYTESTRING
instance NFData BS.ByteString where
#endif
-- | Represents a model that can be instantiated as Torsion topology or
-- Cartesian topology.
class Model m where
torsionTopo :: m -> TorsionTopo
cartesianTopo :: m -> CartesianTopo
-- | Model based on Torsion topology, with cached Cartesian positions.
data TorsionModel = TModel { tTopo :: TorsionTopo
, cTopo :: CartesianTopo
}
instance Model TorsionModel where
cartesianTopo m = debuggingOff $ cTopo m
where
debuggingOff = id
debuggingOn = traceShow ("TorsionModel::cartesianTopo",
length $ filter ((=="CA") . cAtName) $ backbone $ cTopo m)
torsionTopo = tTopo
instance NFData TorsionModel where
rnf a = rnf tTopo `seq` rnf cTopo
-- | Given a monadic action on Torsion topology, lifts it into monadic
-- action on TorsionModel.
modifyTorsionModelM :: (Monad m) => (TorsionTopo -> m TorsionTopo) -> TorsionModel -> m TorsionModel
modifyTorsionModelM topoFun tModel = do tTopo' <- topoFun $ tTopo tModel
return $ TModel tTopo' $ computePositions tTopo'
-- | Creates TorsionModel for a given Torsion topology.
initTorsionModel topo = TModel { tTopo = topo
, cTopo = computePositions topo
}