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
Branches
Tags 1.1.0
No related merge requests found
......@@ -125,6 +125,8 @@ void SDFReader::NextMolecule()
atom_count_=0;
bond_count_=0;
line_num=0;
curr_residue_ = ost::mol::ResidueHandle();
curr_chain_ = ost::mol::ChainHandle();
}
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";
throw IOException(str(format(msg) % line_num));
}
curr_chain_=editor.InsertChain(s_chain);
LOG_DEBUG("new chain " << s_chain);
mol::ResidueKey rkey=boost::trim_copy(s_title);
mol::ResNum rnum(++residue_count_);
curr_residue_=editor.AppendResidue(curr_chain_, rkey, rnum);
LOG_DEBUG("new residue " << rkey << "(" << rnum << ")");
// prepeare required variables to add new chain and residue
// once we parse the first atom
curr_chain_name_ = s_chain;
curr_res_key_ = boost::trim_copy(s_title);
break;
}
case 2: // user information line
......@@ -228,6 +227,17 @@ void SDFReader::ParseAndAddAtom(const String& line, int line_num,
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);
mol::AtomHandle atom=editor.InsertAtom(curr_residue_, aname, apos, upper_ele);
......
......@@ -53,6 +53,8 @@ private:
void ParseAndAddBond(const String& line, int line_num, mol::EntityHandle& ent,
mol::XCSEditor& editor);
String curr_chain_name_;
mol::ResidueKey curr_res_key_;
mol::ChainHandle curr_chain_;
mol::ResidueHandle curr_residue_;
int chain_count_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment