STORMM Source Documentation
Loading...
Searching...
No Matches
mdlmol.h
1// -*-c++-*-
2#ifndef STORMM_MDL_FILE_H
3#define STORMM_MDL_FILE_H
4
5#include <fstream>
6#include <string>
7#include <vector>
8#include "copyright.h"
9#include "Accelerator/hybrid.h"
10#include "Chemistry/znumber.h"
11#include "Chemistry/chemical_features.h"
12#include "Constants/behavior.h"
13#include "DataTypes/common_types.h"
14#include "DataTypes/stormm_vector_types.h"
15#include "FileManagement/file_util.h"
16#include "Parsing/ascii_numbers.h"
17#include "Parsing/parse.h"
18#include "Potential/energy_enumerators.h"
19#include "Restraints/restraint_apparatus.h"
20#include "Synthesis/condensate.h"
21#include "Synthesis/phasespace_synthesis.h"
22#include "Topology/atomgraph.h"
23#include "Topology/atomgraph_abstracts.h"
24#include "Trajectory/coordinateframe.h"
25#include "Trajectory/coordinate_series.h"
26#include "Trajectory/phasespace.h"
27#include "Trajectory/trajectory_enumerators.h"
28#include "molecule_file_io.h"
29#include "molecule_format_enumerators.h"
30#include "mdlmol_atomlist.h"
31#include "mdlmol_bond.h"
32#include "mdlmol_dataitem.h"
33#include "mdlmol_property.h"
34
35namespace stormm {
36namespace structure {
37
38using card::HybridTargetLevel;
39using chemistry::symbolToZNumber;
40using chemistry::ChemicalFeatures;
41using constants::CartesianDimension;
42using constants::CaseSensitivity;
43using constants::ExceptionResponse;
44using data_types::isFloatingPointScalarType;
45using diskutil::PrintSituation;
46using energy::StateVariable;
47using parse::TextFile;
48using restraints::RestraintApparatus;
49using synthesis::Condensate;
50using synthesis::CondensateReader;
51using synthesis::PhaseSpaceSynthesis;
52using synthesis::PsSynthesisReader;
53using topology::AtomGraph;
54using topology::ChemicalDetailsKit;
55using topology::NonbondedKit;
56using trajectory::CoordinateCycle;
57using trajectory::CoordinateFrame;
58using trajectory::CoordinateFrameReader;
59using trajectory::CoordinateFrameWriter;
60using trajectory::CoordinateSeries;
61using trajectory::CoordinateSeriesReader;
62using trajectory::CoordinateSeriesWriter;
63using trajectory::PhaseSpace;
64using trajectory::PhaseSpaceReader;
65using trajectory::PhaseSpaceWriter;
66
69constexpr char4 default_mdl_atomic_symbol = { ' ', ' ', ' ', ' ' };
70constexpr int default_mdl_atomic_number = -1;
71constexpr int default_mdl_formal_charge = 0;
72constexpr RadicalState default_mdl_radical_state = RadicalState::NONE;
73constexpr int default_mdl_isotopic_shift = 0;
74constexpr MolObjAtomStereo default_mdl_stereo_parity = MolObjAtomStereo::NOT_STEREO;
75constexpr HydrogenAssignment default_hydrogenation = HydrogenAssignment::DO_NOT_HYDROGENATE;
76constexpr int default_mdl_implicit_hydrogen = 0;
77constexpr int default_mdl_valence_connections = 0;
78constexpr int default_mdl_map_count = 0;
79constexpr bool default_mdl_stereo_considerations = false;
80constexpr bool default_mdl_exact_change = false;
81constexpr StereoRetention default_mdl_stereo_retention = StereoRetention::NOT_APPLIED;
83
87public:
88private:
89};
90
93
101class MdlMol {
102public:
103
127 MdlMol(ExceptionResponse policy_in = ExceptionResponse::WARN);
128
129 MdlMol(const std::string &filename, ExceptionResponse policy_in = ExceptionResponse::WARN,
130 ModificationPolicy dimod_policy = ModificationPolicy::DO_NOT_MODIFY,
131 ExceptionResponse dimod_notify = ExceptionResponse::WARN);
132
133 MdlMol(const char* filename, ExceptionResponse policy_in = ExceptionResponse::WARN,
134 ModificationPolicy dimod_policy = ModificationPolicy::DO_NOT_MODIFY,
135 ExceptionResponse dimod_notify = ExceptionResponse::WARN);
136
137 MdlMol(const TextFile &tf, int line_start = 0, int line_end = -1,
138 CaseSensitivity capitalization = CaseSensitivity::YES,
139 ExceptionResponse policy_in = ExceptionResponse::WARN,
140 ModificationPolicy dimod_policy = ModificationPolicy::DO_NOT_MODIFY,
141 ExceptionResponse dimod_notify = ExceptionResponse::WARN);
142
143 template <typename T>
144 MdlMol(const ChemicalFeatures *chemfe, const T* xcrd, const T* ycrd, const T* zcrd,
145 double inv_scale, int molecule_index = 0);
146
147 template <typename T>
148 MdlMol(const ChemicalFeatures *chemfe, const T* xcrd, const T* ycrd, const T* zcrd,
149 int molecule_index = 0);
150
151 MdlMol(const ChemicalFeatures *chemfe, const CoordinateFrameReader cfr, int molecule_index = 0);
152
153 MdlMol(const ChemicalFeatures *chemfe, const CoordinateFrame *cf, int molecule_index = 0);
154
155 MdlMol(const ChemicalFeatures &chemfe, const CoordinateFrame &cf, int molecule_index = 0);
156
157 MdlMol(const ChemicalFeatures *chemfe, const PhaseSpaceReader psr, int molecule_index = 0);
158
159 MdlMol(const ChemicalFeatures *chemfe, const PhaseSpace *ps, int molecule_index = 0);
160
161 MdlMol(const ChemicalFeatures &chemfe, const PhaseSpace &ps, int molecule_index = 0);
162
163 template <typename T>
164 MdlMol(const ChemicalFeatures *chemfe, const CoordinateSeriesReader<T> csr, int frame_index,
165 int molecule_index = 0);
166
167 template <typename T>
168 MdlMol(const ChemicalFeatures *chemfe, const CoordinateSeries<T> *cs, int frame_index,
169 int molecule_index = 0);
170
171 template <typename T>
172 MdlMol(const ChemicalFeatures &chemfe, const CoordinateSeries<T> &cs, int frame_index,
173 int molecule_index = 0);
174
175 MdlMol(const ChemicalFeatures *chemfe, const PsSynthesisReader poly_psr, int system_index,
176 int molecule_index = 0);
177
178 MdlMol(const ChemicalFeatures *chemfe, const PhaseSpaceSynthesis *poly_ps, int system_index,
179 int molecule_index = 0);
180
181 MdlMol(const ChemicalFeatures &chemfe, const PhaseSpaceSynthesis &poly_ps, int system_index,
182 int molecule_index = 0);
183
184 MdlMol(const ChemicalFeatures *chemfe, const CondensateReader *cdnsr, int system_index,
185 int molecule_index = 0);
186
187 MdlMol(const ChemicalFeatures *chemfe, const Condensate *cdns, int system_index,
188 int molecule_index = 0);
189
190 MdlMol(const ChemicalFeatures &chemfe, const Condensate &cdns, int system_index,
191 int molecule_index = 0);
193
198 MdlMol(const MdlMol &original) = default;
199 MdlMol(MdlMol &&original) = default;
200 MdlMol& operator=(const MdlMol &original) = default;
201 MdlMol& operator=(MdlMol &&original) = default;
203
205 const std::string& getTitle() const;
206
208 int getAtomCount() const;
209
211 int getBondCount() const;
212
214 int getPropertiesCount() const;
215
218 int getDataItemCount() const;
219
230 double3 getCoordinates(int index) const;
231 const std::vector<double3>& getCoordinates() const;
232 std::vector<double> getCoordinates(CartesianDimension dim) const;
234
237 const MdlMol* getSelfPointer() const;
238
242
246
250 char4 getAtomSymbol(int index) const;
251
253 const std::vector<char4>& getAtomSymbols() const;
254
258 int getAtomicNumber(int index) const;
259
261 const std::vector<int>& getAtomicNumbers() const;
262
266 int getFormalCharge(int index) const;
267
269 const std::vector<int>& getFormalCharges() const;
270
311 template <typename T> void impartCoordinates(const T* xcrd, const T* ycrd, const T* zcrd,
312 double scale_factor);
313
314 template <typename T> void impartCoordinates(const T* xcrd, const T* ycrd, const T* zcrd,
315 double scale_factor, const ChemicalDetailsKit &cdk,
316 int molecule_index);
317
318 void impartCoordinates(const llint* xcrd, const llint* ycrd, const llint* zcrd,
319 const int* xcrd_ovrf, const int* ycrd_ovrf, const int* zcrd_ovrf,
320 double scale_factor);
321
322 void impartCoordinates(const llint* xcrd, const llint* ycrd, const llint* zcrd,
323 const int* xcrd_ovrf, const int* ycrd_ovrf, const int* zcrd_ovrf,
324 double scale_factor, const ChemicalDetailsKit &cdk, int molecule_index);
325
326 void impartCoordinates(const PhaseSpaceReader &psr);
327
328 void impartCoordinates(const PhaseSpaceWriter &psw);
329
330 void impartCoordinates(const PhaseSpace *ps, CoordinateCycle orientation,
331 HybridTargetLevel tier = HybridTargetLevel::HOST);
332
333 void impartCoordinates(const PhaseSpace *ps,
334 HybridTargetLevel tier = HybridTargetLevel::HOST);
335
336 void impartCoordinates(const PhaseSpace &ps, CoordinateCycle orientation,
337 HybridTargetLevel tier = HybridTargetLevel::HOST);
338
339 void impartCoordinates(const PhaseSpace &ps,
340 HybridTargetLevel tier = HybridTargetLevel::HOST);
341
343
345
346 void impartCoordinates(const CoordinateFrame *cf,
347 HybridTargetLevel tier = HybridTargetLevel::HOST);
348
349 void impartCoordinates(const CoordinateFrame &cf,
350 HybridTargetLevel tier = HybridTargetLevel::HOST);
351
352 template <typename T>
353 void impartCoordinates(const CoordinateSeriesReader<T> &cs, int frame_index,
354 HybridTargetLevel tier = HybridTargetLevel::HOST);
355
356 template <typename T>
357 void impartCoordinates(const CoordinateSeriesWriter<T> &cs, int frame_index,
358 HybridTargetLevel tier = HybridTargetLevel::HOST);
359
360 template <typename T>
361 void impartCoordinates(const CoordinateSeries<T> *cs, int frame_index,
362 HybridTargetLevel tier = HybridTargetLevel::HOST);
363
364 template <typename T>
365 void impartCoordinates(const CoordinateSeries<T> &cs, int frame_index,
366 HybridTargetLevel tier = HybridTargetLevel::HOST);
367
368 void impartCoordinates(const PhaseSpaceSynthesis *poly_ps, int system_index,
369 HybridTargetLevel tier = HybridTargetLevel::HOST);
370
371 void impartCoordinates(const PhaseSpaceSynthesis &poly_ps, int system_index,
372 HybridTargetLevel tier = HybridTargetLevel::HOST);
374
385 void addProperty(const MdlMolProperty *mmprop);
386 void addProperty(const MdlMolProperty &mmprop);
388
406 void addDataItem(const MdlMolDataRequest &ask, const AtomGraph &ag,
407 const RestraintApparatus &ra);
409
413 MdlMolDataItemKind getDataItemKind(int item_index) const;
414
416 StateVariable getTrackedState(int item_index) const;
417
424 void addLineToDataItem(const std::string &text, int item_index);
425
429 const std::string& getDataItemName(int item_index) const;
430
435 const std::string& getDataItemOutputName(int item_index) const;
436
440 int getDataItemIndex(const std::string &item_name) const;
441
453 const std::vector<std::string>& getDataItemContent(int item_index) const;
454 std::vector<std::string> getDataItemContent(const std::string &item_name) const;
456
477 void writeMdl(std::ofstream *foutp, MdlMolVersion vformat) const;
478
479 void writeMdl(const std::string &fname, MdlMolVersion vformat, PrintSituation expectation) const;
480
481 std::string writeMdl(MdlMolVersion vformat = MdlMolVersion::V3000) const;
483
499 void writeDataItems(std::ofstream *foutp, int mol_index = 0) const;
500
501 void writeDataItems(const std::string &fname, PrintSituation expectation,
502 int mol_index = 0) const;
503
504 std::string writeDataItems(int mol_index = 0) const;
506
507private:
508
509 // Items describing quantities of information (most of them from the counts line)
510 ExceptionResponse policy;
511 MdlMolVersion version_no;
513 int atom_count;
514 int bond_count;
515 int list_count;
516 int stext_entry_count;
517 int properties_count;
519 int sgroup_count;
520 int constraint_count;
521 MolObjChirality chirality;
522 int registry_number;
523 int data_item_count;
524
525 // Atomic properties
526 bool property_formal_charges;
532 bool property_radicals;
536 bool property_isotopes;
540 bool property_element_lists;
545 std::vector<double3> coordinates;
546 std::vector<char4> atomic_symbols;
547 std::vector<int> atomic_numbers;
548 std::vector<int> formal_charges;
549 std::vector<RadicalState> radicals;
551 std::vector<int> isotopic_shifts;
553 std::vector<MolObjAtomStereo> parities;
554 std::vector<int> implicit_hydrogens;
557 std::vector<bool> stereo_considerations;
562 std::vector<int> valence_connections;
564 std::vector<int> atom_atom_mapping_count;
566 std::vector<bool> exact_change_enforced;
568
572 std::vector<HydrogenAssignment> hydrogenation_protocol;
573
575 std::vector<StereoRetention> orientation_stability;
576
578 std::vector<MdlMolBond> bonds;
579
581 std::vector<MdlMolAtomList> element_lists;
582
584 std::vector<MolObjSTextGroup> stext_entries;
585
587 std::vector<MdlMolProperty> properties;
588
592 std::vector<MdlMolDataItem> data_items;
593
595 std::string title;
596
598 std::string software_details;
599
601 std::string general_comment;
602
605 std::string external_regno;
606
611 void validateAtomIndex(int index, const char* caller) const;
612
623 void allocate();
624 void allocate(const ChemicalDetailsKit &cdk, const NonbondedKit<double> &nbk, int mol_idx = 0);
626
635 int getIsotopicShiftCode(int atom_index) const;
636
643 void interpretFormalCharge(int charge_in, int atom_index);
644
649 int getFormalChargeCode(int atom_index) const;
650
654 MolObjAtomStereo interpretStereoParity(int setting_in);
655
665 void interpretImplicitHydrogenContent(int nh_in, int atom_index);
666
671 int getImplicitHydrogenCode(const int atom_index) const;
672
677 bool interpretBooleanValue(int value_in, const std::string &desc);
678
683 int interpretValenceNumber(int count_in);
684
688 StereoRetention interpretStereoStability(int code_in);
689
692 void updateV2kAtomAttributes();
693
696 void hydrogenate();
697
707 void compareExternalRegistryNumbers(const std::string &regno_in);
708
712 void checkAtomCount(int ext_atom_count) const;
713
718 void checkDataItemIndex(int item_index, const char* caller) const;
719
727 void addAtomIntProperty(const std::vector<int2> &notable_data, const char4 prcode);
728
736 void transferTopologicalDetails(const ChemicalFeatures *chemfe, int molecule_index = 0);
737};
738
753std::vector<MdlMol> readStructureDataFile(const TextFile &tf, int low_frame_limit,
754 int high_frame_limit,
755 CaseSensitivity capitalization = CaseSensitivity::YES,
756 ExceptionResponse policy = ExceptionResponse::WARN);
757std::vector<MdlMol> readStructureDataFile(const std::string &file_name,
758 CaseSensitivity capitalization = CaseSensitivity::YES,
759 ExceptionResponse policy = ExceptionResponse::WARN);
760
761std::vector<MdlMol> readStructureDataFile(const TextFile &tf,
762 CaseSensitivity capitalization = CaseSensitivity::YES,
763 ExceptionResponse policy = ExceptionResponse::WARN);
765
766} // namespace structure
767} // namespace stormm
768
769#include "mdlmol.tpp"
770
771#endif
An object to store information about chemical motifs: participation in rings, planarity,...
Definition chemical_features.h:400
Structure for translating a text file into a compact, rapidly parsable vector of characters in CPU RA...
Definition textfile.h:45
A collection of all restraints pertaining to a specific topology for the purposes of one simulation,...
Definition restraint_apparatus.h:109
A request for one of a sanctioned list of information types to be included in a data item of an SD fi...
Definition mdlmol_request.h:20
A molecular or atomic property read from an MDL .mol or SDF file.
Definition mdlmol_property.h:17
const std::vector< std::string > & getDataItemContent(int item_index) const
Get the lines from a data item as an array of strings.
Definition mdlmol.cpp:1096
const std::string & getTitle() const
Get the title of the MDL MOL entry (for its first three lines)
Definition mdlmol.cpp:417
const std::string & getDataItemName(int item_index) const
Get the name of a data item based on its number.
Definition mdlmol.cpp:1074
const std::vector< int > & getAtomicNumbers() const
Get a const reference to the vector of all atomic numbers in the system.
Definition mdlmol.cpp:517
void addLineToDataItem(const std::string &text, int item_index)
Add a line of text to a specific data item within the MDL MOL entry. This text may contain a pre-form...
Definition mdlmol.cpp:1068
void impartCoordinates(const T *xcrd, const T *ycrd, const T *zcrd, double scale_factor)
Impart a new set of coordinates to the atoms based on one of STORMM's major coordinate classes....
const std::vector< int > & getFormalCharges() const
Get a const reference to the vector of all formal charges.
Definition mdlmol.cpp:528
const std::string & getDataItemOutputName(int item_index) const
Get the name of a data item based on its number, fit for output in the proper Biovia SD file format s...
Definition mdlmol.cpp:1080
int getDataItemIndex(const std::string &item_name) const
Get the index of a data item based on a name.
Definition mdlmol.cpp:1086
char4 getAtomSymbol(int index) const
Get the atomic symbol for a particular atom.
Definition mdlmol.cpp:500
int getBondCount() const
Get the number of bonds in the system.
Definition mdlmol.cpp:427
double3 getCoordinates(int index) const
Get the { X, Y, Z } coordinate tuple for a particular atom, or for all atoms.
Definition mdlmol.cpp:442
StateVariable getTrackedState(int item_index) const
Get the state variable that one of the data items is tracking.
Definition mdlmol.cpp:1062
MdlMol(ExceptionResponse policy_in=ExceptionResponse::WARN)
Constructors for the MDL molecule format object (known as MolObj in RDKit)
Definition mdlmol.cpp:34
int getAtomCount() const
Get the system's atom count.
Definition mdlmol.cpp:422
int getDataItemCount() const
Get the number of data items (XML-like note found after the MDL section of the entry in a BIOVIA Stru...
Definition mdlmol.cpp:437
const std::vector< char4 > & getAtomSymbols() const
Get a const reference to the atomic symbols for all atoms.
Definition mdlmol.cpp:506
void addProperty(const MdlMolProperty *mmprop)
Add a property to the object. Properties must follow a list of pre-approved BIOVIA codes,...
Definition mdlmol.cpp:692
const MdlMol * getSelfPointer() const
Get a const pointer to the object, useful if a pointer is needed and the object is available by const...
Definition mdlmol.cpp:471
int getFormalCharge(int index) const
Get the formal charge on a particular atom.
Definition mdlmol.cpp:522
void writeMdl(std::ofstream *foutp, MdlMolVersion vformat) const
Write a set of molecular coordinates, bonds, and their annotations in MDL MOL format....
Definition mdlmol.cpp:1113
void writeDataItems(std::ofstream *foutp, int mol_index=0) const
Write the non-MDL components of an SD file, including all applicable data items, to a string or file....
Definition mdlmol.cpp:1211
MdlMol(const MdlMol &original)=default
Default copy and move constructors, as well as assignment operators, are appropriate for this object ...
CoordinateFrame exportCoordinateFrame() const
Export the coordinates as a stripped-down CoordinateFrame object suitable for molecular mechanics ene...
Definition mdlmol.cpp:488
PhaseSpace exportPhaseSpace() const
Export the coordinates as a PhaseSpace object suitable for basic molecular mechanics force computatio...
Definition mdlmol.cpp:476
void addDataItem(const MdlMolDataRequest &ask, const AtomGraph &ag, const RestraintApparatus &ra)
Add a data item to the object. These data items follow the classifications set forth in the DataReque...
Definition mdlmol.cpp:697
int getPropertiesCount() const
Get the number of properties found in the MDL MOL entry.
Definition mdlmol.cpp:432
MdlMolDataItemKind getDataItemKind(int item_index) const
Get the classification of a data item from within the MDL MOL entry.
Definition mdlmol.cpp:1056
int getAtomicNumber(int index) const
Get the atomic number of a particular atom.
Definition mdlmol.cpp:511
An SText group from an MDL MOL (.mol) or SDF file. This information is used only by old ISIS / Deskto...
Definition mdlmol.h:86
Condense the data format, and possibly offer a reduced representation of coordinates,...
Definition condensate.h:146
A fixed-precision representation of coordinates, velocities, and forces to manage a set of simulation...
Definition phasespace_synthesis.h:325
A struct to hold information relating to an Amber topology. This struct's member functions are limite...
Definition atomgraph.h:50
Store the coordinates and box information for a frame, only. This abridged struct can serve when the ...
Definition coordinateframe.h:111
Store the coordinates and box information for a series of frames, in one of several levels of precisi...
Definition coordinate_series.h:137
An object to complement a topology and hold positions, velocities, and forces of all particles in a s...
Definition phasespace.h:141
Definition stormm_vector_types.h:141
Definition stormm_vector_types.h:117
Read-only abstract for the Condensate class. In most cases, the read-only abstract will be preferred ...
Definition condensate.h:102
The reader for a PhaseSpaceSynthesis object, containing all of the data relevant for propagating dyna...
Definition phasespace_synthesis.h:199
Information on atoms and residues which may be useful for applying atom masks or identifying specific...
Definition atomgraph_abstracts.h:382
Information needed for non-bonded real-space calculations. Templating is used as above,...
Definition atomgraph_abstracts.h:287
Collect C-style pointers for the elements of a read-only CoordinateFrame object.
Definition coordinateframe.h:65
Collect C-style pointers for the elements of a writable CoordinateFrame object.
Definition coordinateframe.h:30
Collect C-style pointers and critical constants for a read-only CoordinateSeries object.
Definition coordinate_series.h:96
Collect C-style pointers and critical constants for a writeable CoordinateSeries object.
Definition coordinate_series.h:66
Collect constants and pointers to the components of a read-only PhaseSpace object.
Definition phasespace.h:81
Collect constants and pointers to the components of a modifiable PhaseSpace object.
Definition phasespace.h:31