ccp4srs  Version 1.0.0
ccp4srs_base.h
Go to the documentation of this file.
1 // $Id: ccp4srs_base.h $
2 // =================================================================
3 //
4 // CCP4 SRS Library: Storage, Retrieval and Search support for
5 // CCP4 ligand data.
6 //
7 // Copyright (C) Eugene Krissinel 2010-2013.
8 //
9 // This library is free software: you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License version 3, modified in accordance with the provisions
12 // of the license to address the requirements of UK law.
13 //
14 // You should have received a copy of the modified GNU Lesser
15 // General Public License along with this library. If not, copies
16 // may be downloaded from http://www.ccp4.ac.uk/ccp4license.php
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Lesser General Public License for more details.
22 //
23 // =================================================================
24 //
25 // 03.02.14 <-- Date of Last Modification.
26 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 // -----------------------------------------------------------------
28 //
29 // **** Module : ccp4srs_base <interface>
30 // ~~~~~~~~~
31 // **** Classes : ccp4srs::Base - SRS base manager class
32 // ~~~~~~~~~
33 //
34 // (C) E. Krissinel 2010-2014
35 //
36 // =================================================================
37 //
38 
39 #ifndef CCP4SRS_BASE_H
40 #define CCP4SRS_BASE_H
41 
42 #include "ccp4srs_index.h"
43 #include "mmdb2/mmdb_math_graph.h"
44 
45 namespace ccp4srs {
46 
47  // ==================================================================
48 
49  DefineClass(Base);
50 
51  class Base {
52 
53  public:
54 
55  Base ();
56  ~Base();
57 
58  // LoadIndex() loads index of the structural database. 'srsPath'
59  // must point on the directory containing the database files.
60  // The index must be loaded once before retrieving any
61  // information from the database.
62  // LoadIndex() may return either CCP4SRS_Ok, CCP4SRS_CorruptIndex
63  // or CCP4SRS_FileNotFound.
64  int loadIndex ( mmdb::cpstr srsPath );
65 
66  // LoadStructure(..) reads structure from *.srs files and
67  // stores it in RAM for faster access. There is no special
68  // functions to access loaded structures, all requests to
69  // *.srs files and RAM-storage are dispatched automatically.
70  int loadStructure ( mmdb::cpstr entryID );
71 
72  PIndex getIndex ( mmdb::cpstr entryID );
73  PIndex getIndex ( int n );
74 
75  // UnloadStructure(..) deletes strtucture from RAM and releases
76  // its memory. The structure is then accessible in the normal
77  // way from *.srs files, which is slower.
78  int unloadStructure ( mmdb::cpstr entryID );
79 
80  // GetPath() returns full path to a file with file name FName
81  // in the database directory. Length of S should suffice for
82  // accomodating the path. The function returns S.
83  // GetPath() will work only after loading the database index.
84  mmdb::pstr getPath ( mmdb::pstr & S, mmdb::cpstr FName );
85 
86  // GetStructFile() creates and opens the database structure
87  // file and returns its pointer. In the case of errors returns
88  // NULL. Application is responsible for deleting this class.
89  mmdb::io::PFile getStructFile();
90 
91  // GetGraphFile() creates and opens the database graph
92  // file and returns its pointer. In the case of errors returns
93  // NULL. Application is responsible for deleting this class.
94  mmdb::io::PFile getGraphFile();
95 
96  // n_entries() returns number of entries in the database index.
97  inline int n_entries() { return nEntries; }
98 
99  // getEntryNo() returns position of the structure with
100  // (3-letter) name 'name' as found in the database index.
101  // Non-negative return means success, otherwise
102  // CCP4SRS_EntryNotFound indicates that the requested structure
103  // was not found in the database index.
104  int getEntryNo ( mmdb::cpstr entryID );
105 
106  // getMonomer returns pointer to the monomer structure
107  // identified by 3-letter entryID. If such structure is not
108  // found, the function returns NULL.
109  // The function returns a pointer to a private copy of the
110  // structure. Modifying it will not change data in the structural
111  // database. The application is responsible for deallocating
112  // the structure after use (simply use delete).
113  // See description of CCP4SRSMonomer for the explanation of
114  // its fields.
115  PMonomer getMonomer ( mmdb::cpstr entryID );
116 
117  // Another form of getMonomer(..) uses an open structure
118  // file, which allows to save on opening/closing file if
119  // multiple access to SRS structures is required.
120  PMonomer getMonomer ( int entryNo, // 0...nEntries-1
121  mmdb::io::PFile structFile );
122  PMonomer getMonomer ( mmdb::cpstr entryID,
123  mmdb::io::PFile structFile );
124 
125 
131  int getNofAtoms ( mmdb::cpstr entryID );
132 
138  int getNofAtoms ( int entryNo );
139 
146  int getNofAtoms ( int entryNo, int & nNonHAtoms, int & nHAtoms );
147 
157  int getAtNames ( int entryNo, mmdb::PAtomName AtName,
158  int & nAtoms, int & nH );
159 
170  int getAtNames ( mmdb::io::PFile structFile, int entryNo,
171  mmdb::PAtomName AtName, int & nAtoms, int & nH );
172 
187  int getAtoms ( mmdb::cpstr entryID,
188  int & nNonHAtoms, mmdb::PAtomName NonHAtName,
189  int & nHAtoms, mmdb::PAtomName HAtName,
190  mmdb::ivector Hconnect, mmdb::ivector Elem,
191  mmdb::ivector Chiral );
192 
203  int getBonds ( mmdb::cpstr entryID,
204  mmdb::ivector nBonds, mmdb::imatrix bondPair,
205  int & nAtoms, int maxNAtoms,
206  int maxNBonds );
207 
208  int getHetInfo ( mmdb::cpstr entryID,
209  mmdb::pstr Formula,
210  mmdb::pstr Hname,
211  mmdb::pstr Hsynonym,
212  mmdb::pstr Hcharge,
213  mmdb::PAtomName & ClinkAtom, // will
214  mmdb::PElement & ClinkEle, // be
215  mmdb::PAtomName & SlinkAtom, // allocated
216  mmdb::PElement & SlinkEle, // or NULL
217  int & nLeavingAtoms );
218 
219  // getGraph(..) retrieves data for chemical structure number
220  // entryNo (as in Index) from graph file graphFile, then
221  // allocates and builds the corresponding graph, which is
222  // returned in G.
223  // If Hflag is set >= 1, all hydrogens are removed from
224  // the graph. If Hflag is set to 2, element types of atoms,
225  // to which hydrogens are bonded, are modified with flag
226  // HYDROGEN_BOND.
227  // Returns CCP4SRS_Ok in case of success. Other return code are
228  // CCP4SRS_WrongIndex and CCP4SRS_ReadError.
229  int getGraph ( mmdb::io::PFile graphFile, mmdb::math::RPGraph G );
230  int getGraph ( mmdb::io::PFile graphFile, int entryNo,
231  mmdb::math::RPGraph G, int Hflag );
232  int getGraph ( mmdb::io::PFile graphFile, mmdb::math::RPGraph G,
233  int Hflag );
234  int getGraph ( int entryNo, mmdb::math::RPGraph G, int Hflag );
235  int getGraph ( mmdb::cpstr entryID, mmdb::math::RPGraph G,
236  int Hflag );
237 
238 
239  protected:
241  PPIndex index;
242  mmdb::pstr srsDir;
244  int nEntries;
245 
246  void init_base ();
247  void freeMemory();
248 
249  private:
250  int index_alloc;
251 
252  };
253 
254 } // namespace ccp4srs
255 
256 
257 #endif // CCP4SRS_BASE_H
Definition: memio_.h:48
mmdb::pstr getPath(mmdb::pstr &S, mmdb::cpstr FName)
Definition: ccp4srs_base.cpp:157
DefineClass(Angle)
int getAtoms(mmdb::cpstr entryID, int &nNonHAtoms, mmdb::PAtomName NonHAtName, int &nHAtoms, mmdb::PAtomName HAtName, mmdb::ivector Hconnect, mmdb::ivector Elem, mmdb::ivector Chiral)
Retrieves various atom properties for referenced structure.
Definition: ccp4srs_base.cpp:714
int unloadStructure(mmdb::cpstr entryID)
Definition: ccp4srs_base.cpp:151
int loadIndex(mmdb::cpstr srsPath)
Definition: ccp4srs_base.cpp:83
mmdb::pstr srsDir
Definition: ccp4srs_base.h:242
PPIndex index
Definition: ccp4srs_base.h:241
MemIO memIO
Definition: ccp4srs_base.h:240
PIndex getIndex(mmdb::cpstr entryID)
Definition: ccp4srs_base.cpp:134
Definition: ccp4srs_base.h:51
int getBonds(mmdb::cpstr entryID, mmdb::ivector nBonds, mmdb::imatrix bondPair, int &nAtoms, int maxNAtoms, int maxNBonds)
Retrieves bonds for referenced structure.
Definition: ccp4srs_base.cpp:792
int n_entries()
Definition: ccp4srs_base.h:97
int getGraph(mmdb::io::PFile graphFile, mmdb::math::RPGraph G)
Definition: ccp4srs_base.cpp:307
PMonomer getMonomer(mmdb::cpstr entryID)
Definition: ccp4srs_base.cpp:234
int getEntryNo(mmdb::cpstr entryID)
Definition: ccp4srs_base.cpp:164
void freeMemory()
Definition: ccp4srs_base.cpp:66
int getHetInfo(mmdb::cpstr entryID, mmdb::pstr Formula, mmdb::pstr Hname, mmdb::pstr Hsynonym, mmdb::pstr Hcharge, mmdb::PAtomName &ClinkAtom, mmdb::PElement &ClinkEle, mmdb::PAtomName &SlinkAtom, mmdb::PElement &SlinkEle, int &nLeavingAtoms)
Definition: ccp4srs_base.cpp:840
~Base()
Destructor.
Definition: ccp4srs_base.cpp:52
void init_base()
Definition: ccp4srs_base.cpp:56
Definition: ccp4srs_angle.cpp:42
int srsVersion
Definition: ccp4srs_base.h:243
int loadStructure(mmdb::cpstr entryID)
Definition: ccp4srs_base.cpp:146
int nEntries
Definition: ccp4srs_base.h:244
int getNofAtoms(mmdb::cpstr entryID)
Returns the number of atoms in the references monomer.
Definition: ccp4srs_base.cpp:561
Base()
Constructor.
Definition: ccp4srs_base.cpp:48
mmdb::io::PFile getStructFile()
Definition: ccp4srs_base.cpp:205
mmdb::io::PFile getGraphFile()
Definition: ccp4srs_base.cpp:219
int getAtNames(int entryNo, mmdb::PAtomName AtName, int &nAtoms, int &nH)
Returns atom names, total number of atoms and number of hydrogens (nH) for referenced monomer...
Definition: ccp4srs_base.cpp:617