00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 00005 #ifndef BALL_FORMAT_MOL2FILE_H 00006 #define BALL_FORMAT_MOL2FILE_H 00007 00008 #ifndef BALL_FORMAT_GENERICMOLFILE_H 00009 # include <BALL/FORMAT/genericMolFile.h> 00010 #endif 00011 00012 #ifndef BALL_MATHS_VECTOR3_H 00013 # include <BALL/MATHS/vector3.h> 00014 #endif 00015 00016 #ifndef BALL_KERNEL_ATOMCONTAINER_H 00017 # include <BALL/KERNEL/atomContainer.h> 00018 #endif 00019 00020 namespace BALL 00021 { 00022 class Atom; 00023 class System; 00024 00030 class BALL_EXPORT MOL2File 00031 : public GenericMolFile 00032 { 00033 public: 00034 00036 BALL_EXPORT struct SetStruct 00037 { 00038 String name; 00039 bool is_static; 00040 String obj_type; 00041 String sub_type; 00042 String status; 00043 String comment; 00044 Size number_of_members; 00045 00046 vector<Index> static_members; 00047 String dynamic_rule; 00048 }; 00049 00053 00056 static const String TRIPOS; 00058 00062 00065 MOL2File(); 00066 00070 MOL2File(const String& filename, File::OpenMode open_mode = std::ios::in); 00071 00073 virtual ~MOL2File(); 00074 00076 00080 00084 virtual bool write(const System& system); 00085 00089 virtual bool read(System& system); 00090 00094 virtual Molecule* read(); 00095 00099 virtual bool write(const Molecule& molecule); 00100 00102 const MOL2File& operator = (const MOL2File& file); 00103 00105 Size getNumberOfSets() const { return sets_.size(); } 00106 00108 SetStruct& getSet(Position i) { return sets_[i]; } 00109 00111 const SetStruct& getSet(Position i) const { return sets_[i]; } 00112 00114 00115 protected: 00116 00117 void readAtomSection_(); 00118 00119 void readBondSection_(); 00120 00121 void readMoleculeSection_(); 00122 00123 void readSetSection_(); 00124 00125 void readSubstructureSection_(); 00126 00127 void readCommentSection_(); 00128 00129 String getSybylType_(const Atom& atom) const; 00130 00131 bool nextLine_(); 00132 00133 void clear_(); 00134 00135 bool buildAll_(Molecule& molecule); 00136 00137 bool containsAtomChilds_(AtomContainerConstIterator& frag_it); 00138 00139 BALL_EXPORT struct AtomStruct 00140 { 00141 String name; 00142 Vector3 position; 00143 String type; 00144 Position substructure; 00145 String substructure_name; 00146 float charge; 00147 }; 00148 00149 BALL_EXPORT struct BondStruct 00150 { 00151 Position atom1; 00152 Position atom2; 00153 String type; 00154 }; 00155 00156 BALL_EXPORT struct MoleculeStruct 00157 { 00158 String name; 00159 Size number_of_atoms; 00160 Size number_of_bonds; 00161 Size number_of_substructures; 00162 Size number_of_features; 00163 Size number_of_sets; 00164 String type; 00165 String charge_type; 00166 String comment; 00167 }; 00168 00169 BALL_EXPORT struct SubstructureStruct 00170 { 00171 String name; 00172 Size root_atom; 00173 String substructure_type; 00174 Size dictionary_type; 00175 String chain; 00176 String sub_type; 00177 Size inter_bonds; 00178 String comment; 00179 }; 00180 00181 BALL_EXPORT struct CommentStruct 00182 { 00183 String name; 00184 String value; 00185 }; 00186 00187 00188 vector<AtomStruct> atoms_; 00189 vector<BondStruct> bonds_; 00190 vector<SetStruct> sets_; 00191 vector<SubstructureStruct> substructures_; 00192 vector<CommentStruct> comments_; 00193 MoleculeStruct molecule_; 00194 00195 Size number_of_lines_; 00196 static const Size MAX_LENGTH_; 00197 char buffer_[4096]; 00198 String line_; 00199 bool found_next_header_; 00200 }; 00201 } // namespace BALL 00202 00203 #endif // BALL_FORMAT_MOL2FILE_H