22 #include <basic/Tracer.hh>
23 #include <utility/string_util.hh>
24 #include <utility/file/FileName.hh>
25 #include <utility/io/izstream.hh>
27 #include <ObjexxFCL/string.functions.hh>
33 static THREAD_LOCAL basic::Tracer
TR(
"core.io.sdf.MolFileIOReader" );
45 utility::io::izstream file( filename );
47 TR <<
"Error: cannot open file " << filename << std::endl;
48 utility_exit_with_message(
"Error opening " + filename );
53 ObjexxFCL::lowercase( ext );
54 if ( ext ==
".mol" || ext ==
".sdf" || ext ==
".pdb" || ext ==
".mol2" || ext ==
".params" ) {
57 TR <<
"Extension of '" << ext <<
"' for file '" << filename <<
"' not recognized - attempting autodetection of type." << std::endl;
58 utility::io::izstream test_type( filename );
60 bool M_END_line =
false;
61 bool dollars_line =
false;
62 bool ATOM_line =
false;
63 bool BOND_line =
false;
64 bool Tripos_line =
false;
65 for ( getline(test_type, line); test_type; getline(test_type, line) ) {
66 if ( utility::startswith(line,
"M END") ) { M_END_line =
true; }
67 if ( utility::startswith(line,
"$$$$") ) { dollars_line =
true; }
68 if ( utility::startswith(line,
"ATOM") ) { ATOM_line =
true; }
69 if ( utility::startswith(line,
"BOND") ) { BOND_line =
true; }
70 if ( utility::startswith(line,
"@<TRIPOS>") ) { Tripos_line =
true; }
72 if ( M_END_line || dollars_line ) {
73 if ( ATOM_line || BOND_line || Tripos_line ) {
74 TR.Warning <<
"Warning: Ambiguous filetype for loading " << filename <<
", assuming SDF." << std::endl;
77 }
else if ( Tripos_line ) {
78 if ( ATOM_line || BOND_line || M_END_line || dollars_line ) {
79 TR.Warning <<
"Warning: Ambiguous filetype for loading " << filename <<
", assuming mol2." << std::endl;
82 }
else if ( ATOM_line && BOND_line ) {
83 if ( Tripos_line || M_END_line || dollars_line ) {
84 TR.Warning <<
"Warning: Ambiguous filetype for loading " << filename <<
", assuming Rosetta params." << std::endl;
87 }
else if ( ATOM_line && ! BOND_line ) {
88 if ( Tripos_line || M_END_line || dollars_line ) {
89 TR.Warning <<
"Warning: Ambiguous filetype for loading " << filename <<
", assuming PDB." << std::endl;
93 TR.Error <<
"ERROR: Unable to autodetermine filetype of molecule file " << filename << std::endl;
94 utility_exit_with_message(
"Can't determine filetype for file " + filename );
102 ObjexxFCL::lowercase( type );
103 utility::vector1< MolFileIOMoleculeOP > molecules;
105 if ( type ==
"mol" || type ==
"sdf" ) {
107 molecules = parser.
parse( file, n_entries );
108 }
else if ( type ==
"mol2" ) {
109 TR.Error <<
"Loading of mol2 files via this method not currently supported." << std::endl;
110 }
else if ( type ==
"pdb" ) {
111 TR.Error <<
"Loading of pdb files via this method not currently supported." << std::endl;
112 }
else if ( type ==
"params" ) {
113 TR.Error <<
"Loading of params files via this method not currently supported." << std::endl;
115 utility_exit_with_message(
"Do not know how to handle molecule file of type " + type );
118 if ( ! molecules.size() ) {
119 TR.Error <<
"Error: Stream contained no recognized molecules!" << std::endl;
130 AtomTypeSetCOP atom_types( ChemicalManager::get_instance()->atom_type_set( atom_type_tag ) );
131 ElementSetCOP elements( ChemicalManager::get_instance()->element_set( elements_tag ) );
132 MMAtomTypeSetCOP mm_atom_types( ChemicalManager::get_instance()->mm_atom_type_set( mm_atom_type_tag ) );
141 if ( molfile_data.size() == 0 ) {
143 utility_exit_with_message(
"ERROR: Cannot convert an empty vector of molecules to a ResidueType.");
146 std::map< core::chemical::sdf::AtomIndex, std::string > index_name_map;
147 ResidueTypeOP restype = molfile_data[1]->convert_to_ResidueType(index_name_map, atom_types, element_type_set, mm_atom_types);
149 TR.Info <<
"Could not load molecule '" << molfile_data[1]->name() <<
"' as a residue type." << std::endl;
153 if ( molfile_data.size() > 1 ) {
155 for (
core::Size ii(1); ii <= molfile_data.size(); ++ii ) {
156 std::map< std::string, core::Vector > location_map;
157 for ( std::map< core::chemical::sdf::AtomIndex, std::string >::const_iterator itr( index_name_map.begin() ), itr_end( index_name_map.end() );
158 itr != itr_end; ++itr ) {
161 location_map[ itr->second ] = atom->position();
164 rotlib->add_rotamer( location_map );
166 restype->rotamer_library_specification( rotlib );
172 utility::vector1< ResidueTypeOP >
179 AtomTypeSetCOP atom_types( ChemicalManager::get_instance()->atom_type_set( atom_type_tag ) );
180 ElementSetCOP elements( ChemicalManager::get_instance()->element_set( elements_tag ) );
181 MMAtomTypeSetCOP mm_atom_types( ChemicalManager::get_instance()->mm_atom_type_set( mm_atom_type_tag ) );
185 utility::vector1< ResidueTypeOP >
192 std::map< std::string, core::Size > name_index_map;
193 utility::vector1< utility::vector1< MolFileIOMoleculeOP > > separated_molecules;
196 for (
core::Size ii(1); ii <= molfile_data.size(); ++ii ) {
197 if ( ! load_rotamers ) {
198 separated_molecules.resize( separated_molecules.size() + 1 );
199 separated_molecules[ separated_molecules.size() ].push_back( molfile_data[ii] );
200 }
else if ( previous_entry !=
"" && molfile_data[ii]->name() ==
"" ) {
202 separated_molecules[ name_index_map[ previous_entry ] ].push_back( molfile_data[ii] );
203 }
else if ( name_index_map.find( molfile_data[ii]->name() ) != name_index_map.end() ) {
205 separated_molecules[ name_index_map[ molfile_data[ii]->name() ] ].push_back( molfile_data[ii] );
206 previous_entry = molfile_data[ii]->name();
209 separated_molecules.resize( separated_molecules.size() + 1 );
210 separated_molecules[ separated_molecules.size() ].push_back( molfile_data[ii] );
211 name_index_map[ molfile_data[ii]->name() ] = separated_molecules.size();
212 previous_entry = molfile_data[ii]->name();
216 utility::vector1< ResidueTypeOP > residue_types;
217 for (
core::Size jj(1); jj <= separated_molecules.size(); ++jj ) {
218 TR.Debug <<
"Converting " << separated_molecules[jj][1]->name() << std::endl;
223 TR <<
">>>>>> Skipping " << separated_molecules[jj][1]->name() <<
" due to Error: " << e.msg() << std::endl;
226 TR <<
">>>>>> Skipping " << separated_molecules[jj][1]->name() <<
" due to unspecified error!" << std::endl;
230 residue_types.push_back( restype );
234 return residue_types;
ResidueTypeOP convert_to_ResidueType(utility::vector1< MolFileIOMoleculeOP > molfile_data, std::string atom_type_tag, std::string elements_tag, std::string mm_atom_type_tag)
Convert the vector of MolFileIOMolecules into a single residue type, using multiple entries as rotame...
utility::vector1< ResidueTypeOP > convert_to_ResidueTypes(utility::vector1< MolFileIOMoleculeOP > molfile_data, bool load_rotamers, std::string atom_type_tag, std::string elements_tag, std::string mm_atom_type_tag)
Convert the vector of MolFileIOMolecules into multiple residue types If load_rotamers is false...
utility::pointer::shared_ptr< MolFileIOAtom > MolFileIOAtomOP
utility::pointer::shared_ptr< ResidueType > ResidueTypeOP
utility::vector1< MolFileIOMoleculeOP > parse_file(std::string const &filename, std::string type="", core::Size n_entries=0)
parse file, with the possibility of type autodetection.
utility::pointer::shared_ptr< StoredRotamerLibrarySpecification > StoredRotamerLibrarySpecificationOP
Method declarations and simple accessors/getters for ResidueType.
A class which stores atom coordinates for a rotamer library. Internally, this is stored as a list of ...
Chemical manager class header.
std::string filename(core::Size batch_id)
utility::pointer::shared_ptr< MMAtomTypeSet const > MMAtomTypeSetCOP
The StoredRotamerLibrarySpecification class says to build a rotamer library from a set of stored coor...
utility::file::FileName FileName
utility::vector1< MolFileIOMoleculeOP > parse(std::istream &filein, core::Size n_entries=0)
parse the given input stream. n_entries are the maximum number of entries to parse - of zero parse al...
virtual ~MolFileIOReader()
static THREAD_LOCAL basic::Tracer TR("core.chemical.sdf.CtabV2000Parser")
utility::pointer::shared_ptr< ElementSet const > ElementSetCOP
utility::pointer::shared_ptr< AtomTypeSet const > AtomTypeSetCOP