// $Id: mmdb_chain.h $ // ================================================================= // // CCP4 Coordinate Library: support of coordinate-related // functionality in protein crystallography applications. // // Copyright (C) Eugene Krissinel 2000-2013. // // This library is free software: you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License version 3, modified in accordance with the provisions // of the license to address the requirements of UK law. // // You should have received a copy of the modified GNU Lesser // General Public License along with this library. If not, copies // may be downloaded from http://www.ccp4.ac.uk/ccp4license.php // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // ================================================================= // // 12.09.13 <-- Date of Last Modification. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ----------------------------------------------------------------- // // **** Module : MMDB_Chain // ~~~~~~~~~ // **** Project : MacroMolecular Data Base (MMDB) // ~~~~~~~~~ // **** Classes : mmdb::ProModel ( a virtue of Model ) // ~~~~~~~~~ mmdb::DBReference ( DBREF records ) // mmdb::ChainContainer ( container of in-chain classes ) // mmdb::ContainerChain ( chain containered class template) // mmdb::SeqAdv ( SEQADV records ) // mmdb::SeqRes ( SEQRES records ) // mmdb::ModRes ( MODRES records ) // mmdb::HetRec ( HET records ) // mmdb::Chain ( chain class ) // // Copyright (C) E. Krissinel 2000-2013 // // ================================================================= // #ifndef __MMDB_Chain__ #define __MMDB_Chain__ #include "mmdb_io_stream.h" #include "mmdb_utils.h" #include "mmdb_atom.h" #include "mmdb_defs.h" namespace mmdb { // ==================== ProModel ====================== // This class is a virtue needed only for defining certain // functions of Model, which are used by Chain and // Residue DefineClass(ProModel); DefineStreamFunctions(ProModel); DefineClass(Manager); class ProModel : public UDData { friend class Chain; public : ProModel () : UDData () {} ProModel ( io::RPStream Object ) : UDData ( Object ) {} ~ProModel () {} virtual cpstr GetEntryID () { return ""; } virtual void SetEntryID ( const IDCode ) {} virtual int AddChain ( PChain ) { return 0; } // returns pointer to Root virtual PManager GetCoordHierarchy() { return NULL; } // GetNumberOfModels() returns TOTAL number of models virtual int GetNumberOfModels() { return 0; } // GetNumberOfAllAtoms() returns TOTAL number of atoms in // all models virtual int GetNumberOfAllAtoms() { return 0; } // returns pointer to the general Atom array virtual PPAtom GetAllAtoms() { return NULL; } virtual int GetSerNum () { return 0; } virtual void ExpandAtomArray ( int ) {} virtual void AddAtomArray ( int ) {} protected : virtual int _ExcludeChain ( const ChainID ) { return 0; } }; // ==================== ChainContainer ====================== DefineClass(ChainContainer); DefineStreamFunctions(ChainContainer); class ChainContainer : public ClassContainer { public : ChainContainer () : ClassContainer () {} ChainContainer ( io::RPStream Object ) : ClassContainer ( Object ) {} ~ChainContainer () {} PContainerClass MakeContainerClass ( int ClassID ); void SetChain ( PChain Chain_Owner ); // must be set before using // the Container // special functions used in Model::GetCIF(..) cpstr Get1stChainID (); void MoveByChainID ( const ChainID chainID, PChainContainer chainContainer ); protected : PChain chain; }; // ================== ContainerChain ===================== DefineClass(ContainerChain); DefineStreamFunctions(ContainerChain); class ContainerChain : public ContainerClass { friend class ChainContainer; public : ContainerChain (); ContainerChain ( PChain Chain_Owner ); ContainerChain ( io::RPStream Object ) : ContainerClass(Object) {} void SetChain ( PChain Chain_Owner ); protected : PChain chain; ChainID chainID; // just a copy of Chain->chainID }; // ================== DBReference ======================== DefineClass(DBReference); DefineStreamFunctions(DBReference); class DBReference : public ContainerChain { public : int seqBeg; // initial seq num of the PDB seq-ce segment InsCode insBeg; // initial ins code of the PDB seq-ce segm-t int seqEnd; // ending seq number of the PDB seq-ce segm-t InsCode insEnd; // ending ins code of the PDB seq-ce segment DBName database; // sequence database name DBAcCode dbAccession; // sequence database accession code DBIdCode dbIdCode; // sequence database identification code int dbseqBeg; // initial seq number of the database segment InsCode dbinsBeg; // ins code of initial residue of the segment int dbseqEnd; // ending seq number of the database segment InsCode dbinsEnd; // ins code of the ending residue of the seg-t DBReference (); DBReference ( PChain Chain_Owner ); DBReference ( PChain Chain_Owner, cpstr S ); DBReference ( io::RPStream Object ); ~DBReference(); void PDBASCIIDump ( pstr S, int N ); void MakeCIF ( mmcif::PData CIF, int N ); ERROR_CODE ConvertPDBASCII ( cpstr S ); ERROR_CODE GetCIF ( mmcif::PData CIF, int & n ); CLASS_ID GetClassID () { return ClassID_DBReference; } void Copy ( PContainerClass DBRef ); void write ( io::RFile f ); void read ( io::RFile f ); protected : void InitDBReference(); }; // ==================== SeqAdv =========================== DefineClass(SeqAdv); DefineStreamFunctions(SeqAdv); class SeqAdv : public ContainerChain { public : ResName resName; // residue name in conflict int seqNum; // residue sequence number InsCode insCode; // residue insertion code DBName database; // sequence database name DBAcCode dbAccession; // sequence database accession code ResName dbRes; // sequence database residue name int dbSeq; // sequence database sequence number pstr conflict; // conflict comment SeqAdv (); SeqAdv ( PChain Chain_Owner ); SeqAdv ( PChain Chain_Owner, cpstr S ); SeqAdv ( io::RPStream Object ); ~SeqAdv(); void PDBASCIIDump ( pstr S, int N ); ERROR_CODE ConvertPDBASCII ( cpstr S ); void MakeCIF ( mmcif::PData CIF, int N ); ERROR_CODE GetCIF ( mmcif::PData CIF, int & n ); CLASS_ID GetClassID () { return ClassID_SeqAdv; } void Copy ( PContainerClass seqAdv ); void write ( io::RFile f ); void read ( io::RFile f ); protected : void InitSeqAdv(); }; // ================== SeqRes ======================== DefineClass(SeqRes); DefineStreamFunctions(SeqRes); class SeqRes : public io::Stream { friend class Model; friend class Chain; public : int numRes; // number of residues in the chain PResName resName; // residue names SeqRes (); SeqRes ( io::RPStream Object ); ~SeqRes(); void SetChain ( PChain Chain_Owner ); void PDBASCIIDump ( io::RFile f ); ERROR_CODE ConvertPDBASCII ( cpstr S ); void MakeCIF ( mmcif::PData CIF ); ERROR_CODE GetCIF ( mmcif::PData CIF ); void Copy ( PSeqRes seqRes ); void write ( io::RFile f ); void read ( io::RFile f ); protected : PChain chain; ChainID chainID; int serNum; void InitSeqRes(); void FreeMemory(); }; // ================== ModRes ======================== DefineClass(ModRes); DefineStreamFunctions(ModRes); class ModRes : public ContainerChain { public : ResName resName; // residue name used int seqNum; // residue sequence number InsCode insCode; // residue insertion code ResName stdRes; // standard residue name pstr comment; // description of the residue modification ModRes (); ModRes ( PChain Chain_Owner ); ModRes ( PChain Chain_Owner, cpstr S ); ModRes ( io::RPStream Object ); ~ModRes(); void PDBASCIIDump ( pstr S, int N ); void MakeCIF ( mmcif::PData CIF, int N ); ERROR_CODE ConvertPDBASCII ( cpstr S ); ERROR_CODE GetCIF ( mmcif::PData CIF, int & n ); CLASS_ID GetClassID () { return ClassID_ModRes; } void Copy ( PContainerClass modRes ); void write ( io::RFile f ); void read ( io::RFile f ); protected : void InitModRes(); }; // ================== HetRec =========================== DefineClass(HetRec); DefineStreamFunctions(HetRec); class HetRec : public ContainerChain { public : ResName hetID; // Het identifier (right-justified) int seqNum; // sequence number InsCode insCode; // insertion code int numHetAtoms; // number of HETATM records for the // group present in the entry pstr comment; // text describing Het group HetRec (); HetRec ( PChain Chain_Owner ); HetRec ( PChain Chain_Owner, cpstr S ); HetRec ( io::RPStream Object ); ~HetRec(); void PDBASCIIDump ( pstr S, int N ); void MakeCIF ( mmcif::PData CIF, int N ); ERROR_CODE ConvertPDBASCII ( cpstr S ); ERROR_CODE GetCIF ( mmcif::PData CIF, int & n ); CLASS_ID GetClassID () { return ClassID_Het; } void Copy ( PContainerClass Het ); void write ( io::RFile f ); void read ( io::RFile f ); protected : void InitHetRec(); }; // ================= Chain ======================= DefineFactoryFunctions(Chain); class Chain : public UDData { friend class DBReference; friend class SeqAdv; friend class SeqRes; friend class ModRes; friend class HetRec; friend class Residue; friend class Atom; friend class Model; friend class Root; friend class SelManager; friend class BondManager; friend class CoorManager; friend class Manager; public : ChainContainer DBRef; // database reference ChainContainer seqAdv; // SEQADV records SeqRes seqRes; // Sequence residues, SEQRES records ChainContainer modRes; // modification descriptions ChainContainer Het; // non-standard residues descriptions Chain (); // SetModel() MUST be used after this constructor! Chain ( PProModel model, const ChainID chID ); Chain ( io::RPStream Object ); ~Chain(); void FreeAnnotations(); void SetModel ( PProModel model ); void SetChain ( const ChainID chID ); PManager GetCoordHierarchy(); // PRoot // ConvertXXXXX(..) functions do not check for record name // and assume that PDBString is at least 81 symbols long // (including the terminating null). ERROR_CODE ConvertDBREF ( cpstr PDBString ); ERROR_CODE ConvertSEQADV ( cpstr PDBString ); ERROR_CODE ConvertSEQRES ( cpstr PDBString ); ERROR_CODE ConvertMODRES ( cpstr PDBString ); ERROR_CODE ConvertHET ( cpstr PDBString ); // This function should be used for testing purposes only. // A full PDB ASCII dump for all models and chains involved // is done by Root class. void PDBASCIIDump ( io::RFile f ); void PDBASCIIAtomDump ( io::RFile f ); void MakeAtomCIF ( mmcif::PData CIF ); // ----------------- Extracting residues ------------------------- int GetNumberOfResidues(); // returns number of res-s in the chain PResidue GetResidue ( int resNo ); // returns resNo-th residue // in the chain; // 0<=resNo