Skip to content
Snippets Groups Projects
Commit b63721f2 authored by Studer Gabriel's avatar Studer Gabriel
Browse files

Bugfix: SDFReader - only add new chain when first of its atoms is parsed

Previously, a new chain got added at the first newline after $$$$.
So if an sdf file ends with a newline, you got an unwanted empty chain.
parent 8ee6563c
No related branches found
No related tags found
No related merge requests found
...@@ -125,6 +125,8 @@ void SDFReader::NextMolecule() ...@@ -125,6 +125,8 @@ void SDFReader::NextMolecule()
atom_count_=0; atom_count_=0;
bond_count_=0; bond_count_=0;
line_num=0; line_num=0;
curr_residue_ = ost::mol::ResidueHandle();
curr_chain_ = ost::mol::ChainHandle();
} }
void SDFReader::ParseAndAddHeader(const String& line, int line_num, void SDFReader::ParseAndAddHeader(const String& line, int line_num,
...@@ -145,13 +147,10 @@ void SDFReader::ParseAndAddHeader(const String& line, int line_num, ...@@ -145,13 +147,10 @@ void SDFReader::ParseAndAddHeader(const String& line, int line_num,
String msg="Bad molecule name line %d: Line is empty"; String msg="Bad molecule name line %d: Line is empty";
throw IOException(str(format(msg) % line_num)); throw IOException(str(format(msg) % line_num));
} }
curr_chain_=editor.InsertChain(s_chain); // prepeare required variables to add new chain and residue
LOG_DEBUG("new chain " << s_chain); // once we parse the first atom
curr_chain_name_ = s_chain;
mol::ResidueKey rkey=boost::trim_copy(s_title); curr_res_key_ = boost::trim_copy(s_title);
mol::ResNum rnum(++residue_count_);
curr_residue_=editor.AppendResidue(curr_chain_, rkey, rnum);
LOG_DEBUG("new residue " << rkey << "(" << rnum << ")");
break; break;
} }
case 2: // user information line case 2: // user information line
...@@ -228,6 +227,17 @@ void SDFReader::ParseAndAddAtom(const String& line, int line_num, ...@@ -228,6 +227,17 @@ void SDFReader::ParseAndAddAtom(const String& line, int line_num,
throw IOException(str(format(msg) % line_num % s_charge)); throw IOException(str(format(msg) % line_num % s_charge));
} }
if(!curr_chain_.IsValid()) {
curr_chain_=editor.InsertChain(curr_chain_name_);
LOG_DEBUG("new chain " << curr_chain_name_);
}
if(!curr_residue_.IsValid()) {
mol::ResNum rnum(++residue_count_);
curr_residue_=editor.AppendResidue(curr_chain_, curr_res_key_, rnum);
LOG_DEBUG("new residue " << rkey << "(" << rnum << ")");
}
LOG_DEBUG("adding atom " << aname << " (" << s_ele << ") @" << apos); LOG_DEBUG("adding atom " << aname << " (" << s_ele << ") @" << apos);
mol::AtomHandle atom=editor.InsertAtom(curr_residue_, aname, apos, upper_ele); mol::AtomHandle atom=editor.InsertAtom(curr_residue_, aname, apos, upper_ele);
......
...@@ -53,6 +53,8 @@ private: ...@@ -53,6 +53,8 @@ private:
void ParseAndAddBond(const String& line, int line_num, mol::EntityHandle& ent, void ParseAndAddBond(const String& line, int line_num, mol::EntityHandle& ent,
mol::XCSEditor& editor); mol::XCSEditor& editor);
String curr_chain_name_;
mol::ResidueKey curr_res_key_;
mol::ChainHandle curr_chain_; mol::ChainHandle curr_chain_;
mol::ResidueHandle curr_residue_; mol::ResidueHandle curr_residue_;
int chain_count_; int chain_count_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment