diff --git a/modules/base/src/string_ref.hh b/modules/base/src/string_ref.hh index 48ab841055192522f2068cc91a4df79c97ac20c1..21bf024b8c9faf7cb29efbedd2d559c17496ff50 100644 --- a/modules/base/src/string_ref.hh +++ b/modules/base/src/string_ref.hh @@ -28,7 +28,6 @@ #include <ost/base.hh> #include <string.h> #include <vector> -#include <ost/message.hh> #include <ost/module_config.hh> @@ -60,8 +59,7 @@ public: assert(!this->empty()); return *begin_; } - /// \brief find character in StringRef - /// \return iterator position when found, else iterator pointing to the end + const_iterator find(char p) const { const char* s=begin_; while (s!=end_) { @@ -72,22 +70,13 @@ public: } return s; } - - /// \brief returns a substring of the string - /// - /// \param pos the starting position of the substring - /// \param length is the length of the string. if std::string::npos, the - /// substring goes from \p pos to the end of the string - /// The function does on purpose not perform any boundary check in release - /// mode. It's the duty of the caller to make sure the string has the required - /// length. StringRef substr(size_t pos, size_t n=std::string::npos) const { if (n==std::string::npos) { - assert(begin_+pos<=end_); + assert(pos>=0 && begin_+pos<=end_); return StringRef(begin_+pos, this->length()-pos); } else { - assert(begin_+pos+n<=end_); + assert(pos>=0 && begin_+pos+n<=end_); return StringRef(begin_+pos, n); } } diff --git a/modules/io/src/mol/pdb_reader.cc b/modules/io/src/mol/pdb_reader.cc index 7178667b3bc57cf337defa972c4371d830ce3b19..850556679293f37ce1eeeba7e5b32cd65c015f5d 100644 --- a/modules/io/src/mol/pdb_reader.cc +++ b/modules/io/src/mol/pdb_reader.cc @@ -102,6 +102,9 @@ void PDBReader::Init(const boost::filesystem::path& loc) hard_end_=false; skip_next_=false; data_continues_=false; + old_key_=""; + mol_id_=std::make_pair(false, 0); + } void PDBReader::ThrowFaultTolerant(const String& msg) { @@ -114,7 +117,7 @@ void PDBReader::ThrowFaultTolerant(const String& msg) { void PDBReader::ParseCompndEntry (const StringRef& line, int line_num) { - if (line.size()<20) { + if (line.size()<12) { if (profile_.fault_tolerant) { LOG_WARNING("invalid COMPND record on line " << line_num << ": record is too short"); @@ -464,15 +467,18 @@ void PDBReader::AssignMolIds(mol::EntityHandle ent) { for (std::vector<String>::const_iterator chain_iterator = compnd_iterator->chains.begin(); chain_iterator!= compnd_iterator->chains.end(); ++chain_iterator) { + //~ std::cout << "chain: "<<*chain_iterator <<":: "<<std::endl; if (restrict_chains_.size()==0 || (restrict_chains_.find(*chain_iterator)!=String::npos)) { mol::ChainHandle chain=ent.FindChain(*chain_iterator); if (chain) { chain.SetIntProp("mol_id", compnd_iterator->mol_id); }else{ + std::cout << "failedchain: "<<*chain_iterator <<":: "<<std::endl; + std::stringstream ss; - ss << "could not map COMPND record MOL_ID onto chain " - <<*chain_iterator; + ss << "could not map COMPND record MOL_ID onto chain"; + ss <<*chain_iterator; ThrowFaultTolerant(ss.str()); } } @@ -482,9 +488,13 @@ void PDBReader::AssignMolIds(mol::EntityHandle ent) { mol::ChainHandleList ch_list=ent.GetChainList(); for (mol::ChainHandleList::const_iterator chain=ch_list.begin(); chain!=ch_list.end(); ++chain) { + //~ skip HETATM only chains!! if(chain->IsValid()){ if (!chain->HasProp("mol_id")) { - ThrowFaultTolerant("found chain without MOL_ID"); + std::stringstream ss; + ss << "found chain without MOL_ID: "; + ss << chain->GetName(); + LOG_WARNING(ss.str()); } } } diff --git a/modules/io/tests/test_io_pdb.cc b/modules/io/tests/test_io_pdb.cc index 0056bd194eb54d6624482acfdb2eca1e1605c68e..fbf45c67a54fb7c941d5b7b5599d587b813cd947 100644 --- a/modules/io/tests/test_io_pdb.cc +++ b/modules/io/tests/test_io_pdb.cc @@ -143,6 +143,42 @@ BOOST_AUTO_TEST_CASE(test_parse_compnd_record5) } +//~ BOOST_AUTO_TEST_CASE(test_parse_compnd_record6) +//~ { + //~ String fname("testfiles/pdb/1oax.pdb"); + //~ PDBReader reader(fname, IOProfile()); + //~ mol::EntityHandle ent=mol::CreateEntity(); + //~ + //~ reader.Import(ent); + //~ mol::ChainHandle ch = ent.FindChain("I"); + //~ BOOST_CHECK(ch.HasProp("mol_id")==true); + //~ BOOST_CHECK(ch.GetIntProp("mol_id")==1); +//~ + //~ ch = ent.FindChain("L"); + //~ BOOST_CHECK(ch.HasProp("mol_id")==true); + //~ BOOST_CHECK(ch.GetIntProp("mol_id")==2); +//~ } + +BOOST_AUTO_TEST_CASE(test_parse_compnd_record7) +{ + String fname("testfiles/pdb/2p6a.pdb"); + PDBReader reader(fname, IOProfile()); + mol::EntityHandle ent=mol::CreateEntity(); + + reader.Import(ent); + mol::ChainHandle ch = ent.FindChain("A"); + BOOST_CHECK(ch.HasProp("mol_id")==true); + BOOST_CHECK(ch.GetIntProp("mol_id")==1); + ch = ent.FindChain("D"); + BOOST_CHECK(ch.HasProp("mol_id")==true); + BOOST_CHECK(ch.GetIntProp("mol_id")==2); + + ch = ent.FindChain("E"); + BOOST_CHECK(ch.HasProp("mol_id")==true); + BOOST_CHECK(ch.GetIntProp("mol_id")==3); +} + + //COMPND 3 CHAIN: A V; BOOST_AUTO_TEST_CASE(test_parse_compnd_missing_comma_chain_record) {