RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
MOL2FileSource.h
1/***********************************************************************
2 * The rDock program was developed from 1998 - 2006 by the software team
3 * at RiboTargets (subsequently Vernalis (R&D) Ltd).
4 * In 2006, the software was licensed to the University of York for
5 * maintenance and distribution.
6 * In 2012, Vernalis and the University of York agreed to release the
7 * program as Open Source software.
8 * This version is licensed under GNU-LGPL version 3.0 with support from
9 * the University of Barcelona.
10 * http://rdock.sourceforge.net/
11 ***********************************************************************/
12
13#ifndef _RBTMOL2FILESOURCE_H_
14#define _RBTMOL2FILESOURCE_H_
15
16#include "rxdock/BaseMolecularFileSource.h"
17#include "rxdock/ElementFileSource.h"
18#include "rxdock/ParameterFileSource.h"
19
20#include <nlohmann/json.hpp>
21
22using json = nlohmann::json;
23
24namespace rxdock {
25
26// Simple struct for holding MOL2 SUBSTRUCTURE records
28public:
29 MOL2Substructure() : root_atom(0), chain("UNK"), sub_type("UNK") {}
30 MOL2Substructure(const std::string &name, int rr, const std::string &cc,
31 const std::string &ss)
32 : subst_name(name), root_atom(rr), chain(cc), sub_type(ss) {}
33 std::string GetName() const { return subst_name; };
34 int GetRoot() const { return root_atom; };
35 std::string GetChain() const { return chain; };
36 std::string GetType() const { return sub_type; };
37
38 friend void to_json(json &j, const MOL2Substructure &mol2Structure);
39 friend void from_json(const json &j, MOL2Substructure &mol2Structure);
40
41private:
42 std::string subst_name;
43 int root_atom;
44 std::string chain;
45 std::string sub_type;
46};
47
48void to_json(json &j, const MOL2Substructure &mol2Structure);
49void from_json(const json &j, MOL2Substructure &mol2Structure);
50
51// A MOL2SubstructureMap stores MOL2Substructures keyed by SUBSTRUCTURE ID
52// (subst_id)
53typedef std::map<int, MOL2Substructure> MOL2SubstructureMap;
54typedef MOL2SubstructureMap::iterator MOL2SubstructureMapIter;
55typedef MOL2SubstructureMap::const_iterator MOL2SubstructureMapConstIter;
56
58public:
59 static const std::string _CT;
60 // record delimiter strings
61 static const std::string _TRIPOS_DELIM;
62 static const unsigned int _TRIPOS_DELIM_SIZE;
63 static const std::string _IDS_MOL2_RECDELIM;
64
65 MOL2FileSource(const std::string &fileName, bool bImplHydrogens = true);
67
68 friend void to_json(json &j, const MOL2FileSource &mol2FileSrc);
69 friend void from_json(const json &j, MOL2FileSource &mol2FileSrc);
70
71 bool isTitleListSupported() { return true; }
72 bool isAtomListSupported() { return true; }
73 bool isCoordinatesSupported() { return true; }
74 bool isBondListSupported() { return true; }
75 bool isDataSupported() { return false; }
76
77protected:
78 virtual void Parse();
79
80private:
83 MOL2FileSource &operator=(const MOL2FileSource &);
84
85 // Helper functions to clean up atom attributes after parsing the file
86 void SetupAtomParams();
87 void FixImplicitHydrogenCount();
88 void FixHybridState();
89 void FixTriposTypes();
90 void SetupVdWRadii();
91 void RemoveNonPolarHydrogens();
92
93 // Splits subst_name into ID and name components (e.g. ALA27 => ALA and 27)
94 void GetSSIDandName(const std::string &subst_name, int subst_id,
95 std::string &sID, std::string &sName);
96
97 // parser functions (switched by pointers)
98 void ParseRecordMOLECULE(const std::string &aLine);
99 void ParseRecordATOM(const std::string &aLine);
100 void ParseRecordBOND(const std::string &aLine);
101 void ParseRecordSUBSTRUCTURE(const std::string &aLine);
102 void ParseRecordUNSUPPORTED(const std::string &aLine);
103 // get delimiter tag
104 std::string GetMOL2Tag(const std::string &aLine);
105 // parse/tokenize second line (number of atoms, bonds etc) in MOLECULE
106 void ParseCountFields(const std::string &aLine);
107 void Tokenize(const std::string &aString,
108 std::vector<std::string> &aTokensBuf);
109
110 unsigned int m_NL; // No. of lines
111 // data fields in MOLECULE
112 unsigned int nAtoms; // number of atoms
113 unsigned int nBonds; // bonds
114 unsigned int nSubstructures; // substructures
115 unsigned int nFeatures; // features
116 unsigned int nSets; // sets
117
118 // helper data structures used to lookup chain names for each substructure
119 // and to sort atom list into a more sensible order (ordered by substructure
120 // ID)
121 MOL2SubstructureMap m_ssInfo;
122 std::map<int, AtomList> m_ssAtoms;
123
125 m_spElementData; // Elemental data source for vdW radii etc
127 m_spParamSource; // Parameter file source for partial charges etc
128 TriposAtomType m_typer; // Tripos atom typing object
129 bool m_bImplHydrogens;
130};
131
132void to_json(json &j, const MOL2FileSource &mol2FileSrc);
133void from_json(const json &j, MOL2FileSource &mol2FileSrc);
134
135// usual smart pointer
137// function pointer (callback) for Parse()
138typedef void (MOL2FileSource::*fcPtr)(const std::string &);
139
140} // namespace rxdock
141
142#endif // _RBTMOL2FILESOURCE_H_
Definition BaseMolecularFileSource.h:29
Definition MOL2FileSource.h:57
Definition MOL2FileSource.h:27
Definition TriposAtomType.h:28