{-# LANGUAGE NamedFieldPuns, DisambiguateRecordFields, OverloadedStrings #-}-- | High-level output routines for 'Structure'.moduleBio.PDB.StructurePrinter(write,PDBWritable())whereimportPreludehiding(print)importControl.Monad(mapM_)importSystem.IO(Handle)importData.ByteString.Char8asBSimportBio.PDB.StructureimportBio.PDB.IterableimportBio.PDB.Structure.ListasLimportBio.PDB.EventParser.PDBEventPrinterasPRimportBio.PDB.EventParser.PDBEvents-- | ShowS like type for a list of `PDBEvent`s.typePDBEventS=[PDBEvent]->[PDBEvent]-- * Class-based interface for generating PDB events from structure fragments.-- | Writes a structure or its part in a PDB format to a filehandle.write::PDBWritablea=>Handle->a->IO()writehandlestructure=mapM_(PR.printhandle)(pdbEventsstructure)-- | Class generating events for PDB structure fragments.classPDBWritableawherepdbEvents::a->[PDBEvent]pdbEvents=flippdbEventS[]pdbEventS::a->PDBEventSinstancePDBWritableStructurewherepdbEvents=structureEventspdbEventS=error"Structure is closed by definition cannot have continuation!"instancePDBWritableModelwherepdbEventS=modelEventsinstancePDBWritableChainwherepdbEventS=chainEventsinstancePDBWritableResiduewherepdbEventS=residueEventsblankChaininstancePDBWritableAtomwherepdbEventS=atomEventsblankChainblankResidue-- | Helper: blank chain in case we don't know which chain residue belongs to.blankChain::ChainblankChain=Chain{chainId=' ',residues=L.empty}-- | Helper blank residue in case we don't know which residue the atom belongs to.blankResidue::ResidueblankResidue=Residue{resName="UNK",resSeq=0,insCode=' ',atoms=L.empty}-- * Routines for writing event list for fragments of the structure.-- | Generates list of `PDBEvent`s from a given Structure.structureEvents::Structure->[PDBEvent]structureEventss=itfoldrmodelEvents[END]s-- | Generates list of `PDBEvent`s from a given Model.modelEvents::Model->PDBEventSmodelEventsmcont=start:main(ENDMDL:cont)wherestart=MODEL$modelIdmmainc=itfoldrchainEventscm-- | Generates list of `PDBEvent`s from a given Chain.chainEvents::Chain->PDBEventSchainEventschc=itfoldr(residueEventsch)(ter:c)chwhereter=TER{num=atSer+1,-- FIXME: should be lastAtom ch + 1resname=lastResName,chain=chainIdch,resid=lastResSeq,insCode=lastInsCode}Atom{atSerial=atSer}=L.lastatsResidue{resName=lastResName,resSeq=lastResSeq,insCode=lastInsCode,atoms=ats}=L.last.Bio.PDB.Structure.residues$ch-- | Generates list of `PDBEvent`s from a given Residue and its Chain.residueEvents::Chain->Residue->PDBEventSresidueEventschrc=itfoldr(atomEventschr)cr-- | Generates list of `PDBEvent`s from a given Atom, its Residue, and its Chain.atomEvents::Chain->Residue->Atom->PDBEventSatomEvents(Chain{chainId=chid})(Residue{resName=rtype,resSeq=rid,insCode=rins})(Atom{atName=atName,atSerial=atSer,coord=coord,bFactor=bf,occupancy=occ,element=e,segid=sid,charge=ch,hetatm=isHet})c=ATOM{no=atSer,-- TODO: assign atom serial numbersatomtype=atName,restype=rtype,chain=chid,resid=rid,resins=rins,altloc=' ',coords=coord,occupancy=occ,bfactor=bf,segid=sid,elt=e,charge=ch,hetatm=isHet}:c