{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TemplateHaskell #-}
module Bio.Structure
( SecondaryStructure (..)
, Atom (..), Bond (..)
, Residue (..), Chain (..), Model (..)
, StructureModels (..), StructureSerializable (..)
, LocalID (..)
, GlobalID (..)
, atoms, localBonds
, residues
, chains, globalBonds
) where
import Control.DeepSeq (NFData (..))
import Control.Lens (makeLensesFor)
import Data.Text (Text)
import Data.Vector (Vector)
import GHC.Generics (Generic)
import Linear.V3 (V3)
data SecondaryStructure = PiHelix
| Bend
| AlphaHelix
| Extended
| ThreeTenHelix
| Bridge
| Turn
| Coil
| Undefined
deriving (Int -> SecondaryStructure -> ShowS
[SecondaryStructure] -> ShowS
SecondaryStructure -> String
(Int -> SecondaryStructure -> ShowS)
-> (SecondaryStructure -> String)
-> ([SecondaryStructure] -> ShowS)
-> Show SecondaryStructure
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SecondaryStructure] -> ShowS
$cshowList :: [SecondaryStructure] -> ShowS
show :: SecondaryStructure -> String
$cshow :: SecondaryStructure -> String
showsPrec :: Int -> SecondaryStructure -> ShowS
$cshowsPrec :: Int -> SecondaryStructure -> ShowS
Show, SecondaryStructure -> SecondaryStructure -> Bool
(SecondaryStructure -> SecondaryStructure -> Bool)
-> (SecondaryStructure -> SecondaryStructure -> Bool)
-> Eq SecondaryStructure
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SecondaryStructure -> SecondaryStructure -> Bool
$c/= :: SecondaryStructure -> SecondaryStructure -> Bool
== :: SecondaryStructure -> SecondaryStructure -> Bool
$c== :: SecondaryStructure -> SecondaryStructure -> Bool
Eq, (forall x. SecondaryStructure -> Rep SecondaryStructure x)
-> (forall x. Rep SecondaryStructure x -> SecondaryStructure)
-> Generic SecondaryStructure
forall x. Rep SecondaryStructure x -> SecondaryStructure
forall x. SecondaryStructure -> Rep SecondaryStructure x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SecondaryStructure x -> SecondaryStructure
$cfrom :: forall x. SecondaryStructure -> Rep SecondaryStructure x
Generic)
instance NFData SecondaryStructure
newtype GlobalID = GlobalID { GlobalID -> Int
getGlobalID :: Int }
deriving (GlobalID -> GlobalID -> Bool
(GlobalID -> GlobalID -> Bool)
-> (GlobalID -> GlobalID -> Bool) -> Eq GlobalID
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GlobalID -> GlobalID -> Bool
$c/= :: GlobalID -> GlobalID -> Bool
== :: GlobalID -> GlobalID -> Bool
$c== :: GlobalID -> GlobalID -> Bool
Eq, Int -> GlobalID -> ShowS
[GlobalID] -> ShowS
GlobalID -> String
(Int -> GlobalID -> ShowS)
-> (GlobalID -> String) -> ([GlobalID] -> ShowS) -> Show GlobalID
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GlobalID] -> ShowS
$cshowList :: [GlobalID] -> ShowS
show :: GlobalID -> String
$cshow :: GlobalID -> String
showsPrec :: Int -> GlobalID -> ShowS
$cshowsPrec :: Int -> GlobalID -> ShowS
Show, Eq GlobalID
Eq GlobalID
-> (GlobalID -> GlobalID -> Ordering)
-> (GlobalID -> GlobalID -> Bool)
-> (GlobalID -> GlobalID -> Bool)
-> (GlobalID -> GlobalID -> Bool)
-> (GlobalID -> GlobalID -> Bool)
-> (GlobalID -> GlobalID -> GlobalID)
-> (GlobalID -> GlobalID -> GlobalID)
-> Ord GlobalID
GlobalID -> GlobalID -> Bool
GlobalID -> GlobalID -> Ordering
GlobalID -> GlobalID -> GlobalID
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: GlobalID -> GlobalID -> GlobalID
$cmin :: GlobalID -> GlobalID -> GlobalID
max :: GlobalID -> GlobalID -> GlobalID
$cmax :: GlobalID -> GlobalID -> GlobalID
>= :: GlobalID -> GlobalID -> Bool
$c>= :: GlobalID -> GlobalID -> Bool
> :: GlobalID -> GlobalID -> Bool
$c> :: GlobalID -> GlobalID -> Bool
<= :: GlobalID -> GlobalID -> Bool
$c<= :: GlobalID -> GlobalID -> Bool
< :: GlobalID -> GlobalID -> Bool
$c< :: GlobalID -> GlobalID -> Bool
compare :: GlobalID -> GlobalID -> Ordering
$ccompare :: GlobalID -> GlobalID -> Ordering
$cp1Ord :: Eq GlobalID
Ord, (forall x. GlobalID -> Rep GlobalID x)
-> (forall x. Rep GlobalID x -> GlobalID) -> Generic GlobalID
forall x. Rep GlobalID x -> GlobalID
forall x. GlobalID -> Rep GlobalID x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GlobalID x -> GlobalID
$cfrom :: forall x. GlobalID -> Rep GlobalID x
Generic, GlobalID -> ()
(GlobalID -> ()) -> NFData GlobalID
forall a. (a -> ()) -> NFData a
rnf :: GlobalID -> ()
$crnf :: GlobalID -> ()
NFData)
newtype LocalID = LocalID { LocalID -> Int
getLocalID :: Int }
deriving (LocalID -> LocalID -> Bool
(LocalID -> LocalID -> Bool)
-> (LocalID -> LocalID -> Bool) -> Eq LocalID
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LocalID -> LocalID -> Bool
$c/= :: LocalID -> LocalID -> Bool
== :: LocalID -> LocalID -> Bool
$c== :: LocalID -> LocalID -> Bool
Eq, Int -> LocalID -> ShowS
[LocalID] -> ShowS
LocalID -> String
(Int -> LocalID -> ShowS)
-> (LocalID -> String) -> ([LocalID] -> ShowS) -> Show LocalID
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LocalID] -> ShowS
$cshowList :: [LocalID] -> ShowS
show :: LocalID -> String
$cshow :: LocalID -> String
showsPrec :: Int -> LocalID -> ShowS
$cshowsPrec :: Int -> LocalID -> ShowS
Show, Eq LocalID
Eq LocalID
-> (LocalID -> LocalID -> Ordering)
-> (LocalID -> LocalID -> Bool)
-> (LocalID -> LocalID -> Bool)
-> (LocalID -> LocalID -> Bool)
-> (LocalID -> LocalID -> Bool)
-> (LocalID -> LocalID -> LocalID)
-> (LocalID -> LocalID -> LocalID)
-> Ord LocalID
LocalID -> LocalID -> Bool
LocalID -> LocalID -> Ordering
LocalID -> LocalID -> LocalID
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: LocalID -> LocalID -> LocalID
$cmin :: LocalID -> LocalID -> LocalID
max :: LocalID -> LocalID -> LocalID
$cmax :: LocalID -> LocalID -> LocalID
>= :: LocalID -> LocalID -> Bool
$c>= :: LocalID -> LocalID -> Bool
> :: LocalID -> LocalID -> Bool
$c> :: LocalID -> LocalID -> Bool
<= :: LocalID -> LocalID -> Bool
$c<= :: LocalID -> LocalID -> Bool
< :: LocalID -> LocalID -> Bool
$c< :: LocalID -> LocalID -> Bool
compare :: LocalID -> LocalID -> Ordering
$ccompare :: LocalID -> LocalID -> Ordering
$cp1Ord :: Eq LocalID
Ord, (forall x. LocalID -> Rep LocalID x)
-> (forall x. Rep LocalID x -> LocalID) -> Generic LocalID
forall x. Rep LocalID x -> LocalID
forall x. LocalID -> Rep LocalID x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LocalID x -> LocalID
$cfrom :: forall x. LocalID -> Rep LocalID x
Generic, LocalID -> ()
(LocalID -> ()) -> NFData LocalID
forall a. (a -> ()) -> NFData a
rnf :: LocalID -> ()
$crnf :: LocalID -> ()
NFData)
data Atom = Atom { Atom -> GlobalID
atomId :: GlobalID
, Atom -> Int
atomInputIndex :: Int
, Atom -> Text
atomName :: Text
, Atom -> Text
atomElement :: Text
, Atom -> V3 Float
atomCoords :: V3 Float
, Atom -> Int
formalCharge :: Int
, Atom -> Float
bFactor :: Float
, Atom -> Float
occupancy :: Float
}
deriving (Int -> Atom -> ShowS
[Atom] -> ShowS
Atom -> String
(Int -> Atom -> ShowS)
-> (Atom -> String) -> ([Atom] -> ShowS) -> Show Atom
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Atom] -> ShowS
$cshowList :: [Atom] -> ShowS
show :: Atom -> String
$cshow :: Atom -> String
showsPrec :: Int -> Atom -> ShowS
$cshowsPrec :: Int -> Atom -> ShowS
Show, Atom -> Atom -> Bool
(Atom -> Atom -> Bool) -> (Atom -> Atom -> Bool) -> Eq Atom
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Atom -> Atom -> Bool
$c/= :: Atom -> Atom -> Bool
== :: Atom -> Atom -> Bool
$c== :: Atom -> Atom -> Bool
Eq, (forall x. Atom -> Rep Atom x)
-> (forall x. Rep Atom x -> Atom) -> Generic Atom
forall x. Rep Atom x -> Atom
forall x. Atom -> Rep Atom x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Atom x -> Atom
$cfrom :: forall x. Atom -> Rep Atom x
Generic)
instance Ord Atom where
Atom
a1 <= :: Atom -> Atom -> Bool
<= Atom
a2 = Atom -> GlobalID
atomId Atom
a1 GlobalID -> GlobalID -> Bool
forall a. Ord a => a -> a -> Bool
<= Atom -> GlobalID
atomId Atom
a2
instance NFData Atom
data Bond m = Bond { Bond m -> m
bondStart :: m
, Bond m -> m
bondEnd :: m
, Bond m -> Int
bondOrder :: Int
}
deriving (Int -> Bond m -> ShowS
[Bond m] -> ShowS
Bond m -> String
(Int -> Bond m -> ShowS)
-> (Bond m -> String) -> ([Bond m] -> ShowS) -> Show (Bond m)
forall m. Show m => Int -> Bond m -> ShowS
forall m. Show m => [Bond m] -> ShowS
forall m. Show m => Bond m -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Bond m] -> ShowS
$cshowList :: forall m. Show m => [Bond m] -> ShowS
show :: Bond m -> String
$cshow :: forall m. Show m => Bond m -> String
showsPrec :: Int -> Bond m -> ShowS
$cshowsPrec :: forall m. Show m => Int -> Bond m -> ShowS
Show, Bond m -> Bond m -> Bool
(Bond m -> Bond m -> Bool)
-> (Bond m -> Bond m -> Bool) -> Eq (Bond m)
forall m. Eq m => Bond m -> Bond m -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Bond m -> Bond m -> Bool
$c/= :: forall m. Eq m => Bond m -> Bond m -> Bool
== :: Bond m -> Bond m -> Bool
$c== :: forall m. Eq m => Bond m -> Bond m -> Bool
Eq, a -> Bond b -> Bond a
(a -> b) -> Bond a -> Bond b
(forall a b. (a -> b) -> Bond a -> Bond b)
-> (forall a b. a -> Bond b -> Bond a) -> Functor Bond
forall a b. a -> Bond b -> Bond a
forall a b. (a -> b) -> Bond a -> Bond b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Bond b -> Bond a
$c<$ :: forall a b. a -> Bond b -> Bond a
fmap :: (a -> b) -> Bond a -> Bond b
$cfmap :: forall a b. (a -> b) -> Bond a -> Bond b
Functor, (forall x. Bond m -> Rep (Bond m) x)
-> (forall x. Rep (Bond m) x -> Bond m) -> Generic (Bond m)
forall x. Rep (Bond m) x -> Bond m
forall x. Bond m -> Rep (Bond m) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall m x. Rep (Bond m) x -> Bond m
forall m x. Bond m -> Rep (Bond m) x
$cto :: forall m x. Rep (Bond m) x -> Bond m
$cfrom :: forall m x. Bond m -> Rep (Bond m) x
Generic)
instance Ord (Bond LocalID) where
(Bond (LocalID Int
x) (LocalID Int
y) Int
_) <= :: Bond LocalID -> Bond LocalID -> Bool
<= (Bond (LocalID Int
x') (LocalID Int
y') Int
_) | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
x' = Int
y Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
y'
| Bool
otherwise = Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
x'
instance Ord (Bond GlobalID) where
(Bond (GlobalID Int
x) (GlobalID Int
y) Int
_) <= :: Bond GlobalID -> Bond GlobalID -> Bool
<= (Bond (GlobalID Int
x') (GlobalID Int
y') Int
_) | Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
x' = Int
y Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
y'
| Bool
otherwise = Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
x'
instance NFData a => NFData (Bond a)
data Residue = Residue { Residue -> Text
resName :: Text
, Residue -> Int
resNumber :: Int
, Residue -> Char
resInsertionCode :: Char
, Residue -> Vector Atom
resAtoms :: Vector Atom
, Residue -> Vector (Bond LocalID)
resBonds :: Vector (Bond LocalID)
, Residue -> SecondaryStructure
resSecondary :: SecondaryStructure
, Residue -> Text
resChemCompType :: Text
}
deriving (Int -> Residue -> ShowS
[Residue] -> ShowS
Residue -> String
(Int -> Residue -> ShowS)
-> (Residue -> String) -> ([Residue] -> ShowS) -> Show Residue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Residue] -> ShowS
$cshowList :: [Residue] -> ShowS
show :: Residue -> String
$cshow :: Residue -> String
showsPrec :: Int -> Residue -> ShowS
$cshowsPrec :: Int -> Residue -> ShowS
Show, Residue -> Residue -> Bool
(Residue -> Residue -> Bool)
-> (Residue -> Residue -> Bool) -> Eq Residue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Residue -> Residue -> Bool
$c/= :: Residue -> Residue -> Bool
== :: Residue -> Residue -> Bool
$c== :: Residue -> Residue -> Bool
Eq, (forall x. Residue -> Rep Residue x)
-> (forall x. Rep Residue x -> Residue) -> Generic Residue
forall x. Rep Residue x -> Residue
forall x. Residue -> Rep Residue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Residue x -> Residue
$cfrom :: forall x. Residue -> Rep Residue x
Generic, Residue -> ()
(Residue -> ()) -> NFData Residue
forall a. (a -> ()) -> NFData a
rnf :: Residue -> ()
$crnf :: Residue -> ()
NFData)
makeLensesFor [("resAtoms", "atoms"), ("resBonds", "localBonds")] ''Residue
data Chain = Chain { Chain -> Text
chainName :: Text
, Chain -> Vector Residue
chainResidues :: Vector Residue
}
deriving (Int -> Chain -> ShowS
[Chain] -> ShowS
Chain -> String
(Int -> Chain -> ShowS)
-> (Chain -> String) -> ([Chain] -> ShowS) -> Show Chain
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Chain] -> ShowS
$cshowList :: [Chain] -> ShowS
show :: Chain -> String
$cshow :: Chain -> String
showsPrec :: Int -> Chain -> ShowS
$cshowsPrec :: Int -> Chain -> ShowS
Show, Chain -> Chain -> Bool
(Chain -> Chain -> Bool) -> (Chain -> Chain -> Bool) -> Eq Chain
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Chain -> Chain -> Bool
$c/= :: Chain -> Chain -> Bool
== :: Chain -> Chain -> Bool
$c== :: Chain -> Chain -> Bool
Eq, (forall x. Chain -> Rep Chain x)
-> (forall x. Rep Chain x -> Chain) -> Generic Chain
forall x. Rep Chain x -> Chain
forall x. Chain -> Rep Chain x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Chain x -> Chain
$cfrom :: forall x. Chain -> Rep Chain x
Generic, Chain -> ()
(Chain -> ()) -> NFData Chain
forall a. (a -> ()) -> NFData a
rnf :: Chain -> ()
$crnf :: Chain -> ()
NFData)
makeLensesFor [("chainResidues", "residues")] ''Chain
data Model = Model { Model -> Vector Chain
modelChains :: Vector Chain
, Model -> Vector (Bond GlobalID)
modelBonds :: Vector (Bond GlobalID)
}
deriving (Int -> Model -> ShowS
[Model] -> ShowS
Model -> String
(Int -> Model -> ShowS)
-> (Model -> String) -> ([Model] -> ShowS) -> Show Model
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Model] -> ShowS
$cshowList :: [Model] -> ShowS
show :: Model -> String
$cshow :: Model -> String
showsPrec :: Int -> Model -> ShowS
$cshowsPrec :: Int -> Model -> ShowS
Show, Model -> Model -> Bool
(Model -> Model -> Bool) -> (Model -> Model -> Bool) -> Eq Model
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Model -> Model -> Bool
$c/= :: Model -> Model -> Bool
== :: Model -> Model -> Bool
$c== :: Model -> Model -> Bool
Eq, (forall x. Model -> Rep Model x)
-> (forall x. Rep Model x -> Model) -> Generic Model
forall x. Rep Model x -> Model
forall x. Model -> Rep Model x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Model x -> Model
$cfrom :: forall x. Model -> Rep Model x
Generic, Model -> ()
(Model -> ()) -> NFData Model
forall a. (a -> ()) -> NFData a
rnf :: Model -> ()
$crnf :: Model -> ()
NFData)
makeLensesFor [("modelChains", "chains"), ("modelBonds", "globalBonds")] ''Model
class StructureModels a where
modelsOf :: a -> Vector Model
class StructureSerializable a where
serializeModels :: Vector Model -> a