Skip to content
Snippets Groups Projects
Verified Commit 1cd69a8b authored by Xavier Robin's avatar Xavier Robin
Browse files

refactor: separate parse and add

parent 08991a8e
Branches
Tags
No related merge requests found
...@@ -71,11 +71,11 @@ void SDFReader::Import(mol::EntityHandle& ent) ...@@ -71,11 +71,11 @@ void SDFReader::Import(mol::EntityHandle& ent)
} }
if (line_num<=4) { if (line_num<=4) {
ParseAndAddHeader(line, line_num, ent, editor); ParseHeader(line, line_num, ent, editor);
} else if (line_num<=atom_count_+4) { } else if (line_num<=atom_count_+4) {
ParseAndAddAtom(line, line_num, ent, true, editor); AddAtom(ParseAtom(line, line_num), line_num, ent, true, editor);
} else if (line_num<=bond_count_+atom_count_+4) { } else if (line_num<=bond_count_+atom_count_+4) {
ParseAndAddBond(line, line_num, ent, editor); AddBond(ParseBond(line, line_num), line_num, ent, editor);
} else if (boost::iequals(line.substr(0,2), "> ")) { } else if (boost::iequals(line.substr(0,2), "> ")) {
// parse data items // parse data items
int data_header_start = line.find('<'); int data_header_start = line.find('<');
...@@ -129,7 +129,7 @@ void SDFReader::NextMolecule() ...@@ -129,7 +129,7 @@ void SDFReader::NextMolecule()
curr_chain_ = ost::mol::ChainHandle(); curr_chain_ = ost::mol::ChainHandle();
} }
void SDFReader::ParseAndAddHeader(const String& line, int line_num, void SDFReader::ParseHeader(const String& line, int line_num,
mol::EntityHandle& ent, mol::XCSEditor& editor) mol::EntityHandle& ent, mol::XCSEditor& editor)
{ {
LOG_TRACE( "line: [" << line << "]" ); LOG_TRACE( "line: [" << line << "]" );
...@@ -190,9 +190,7 @@ void SDFReader::ParseAndAddHeader(const String& line, int line_num, ...@@ -190,9 +190,7 @@ void SDFReader::ParseAndAddHeader(const String& line, int line_num,
} }
} }
void SDFReader::ParseAndAddAtom(const String& line, int line_num, SDFReader::atom_data SDFReader::ParseAtom(const String& line, int line_num)
mol::EntityHandle& ent, bool hetatm,
mol::XCSEditor& editor)
{ {
LOG_TRACE( "line: [" << line << "]" ); LOG_TRACE( "line: [" << line << "]" );
...@@ -215,6 +213,16 @@ void SDFReader::ParseAndAddAtom(const String& line, int line_num, ...@@ -215,6 +213,16 @@ void SDFReader::ParseAndAddAtom(const String& line, int line_num,
String s_ele=line.substr(31,3); String s_ele=line.substr(31,3);
String s_charge=line.substr(36,3); String s_charge=line.substr(36,3);
return std::make_tuple(anum, s_posx, s_posy, s_posz, s_ele, s_charge);
}
void SDFReader::AddAtom(const atom_data& atom_tuple, int line_num, mol::EntityHandle& ent,
bool hetatm, mol::XCSEditor& editor)
{
int anum;
String s_posx, s_posy, s_posz, s_ele, s_charge;
tie(anum, s_posx, s_posy, s_posz, s_ele, s_charge) = atom_tuple;
geom::Vec3 apos; geom::Vec3 apos;
try { try {
apos=geom::Vec3(boost::lexical_cast<Real>(boost::trim_copy(s_posx)), apos=geom::Vec3(boost::lexical_cast<Real>(boost::trim_copy(s_posx)),
...@@ -262,8 +270,7 @@ void SDFReader::ParseAndAddAtom(const String& line, int line_num, ...@@ -262,8 +270,7 @@ void SDFReader::ParseAndAddAtom(const String& line, int line_num,
} }
void SDFReader::ParseAndAddBond(const String& line, int line_num, SDFReader::bond_data SDFReader::ParseBond(const String& line, int line_num)
mol::EntityHandle& ent, mol::XCSEditor& editor)
{ {
LOG_TRACE( "line: [" << line << "]" ); LOG_TRACE( "line: [" << line << "]" );
...@@ -283,10 +290,20 @@ void SDFReader::ParseAndAddBond(const String& line, int line_num, ...@@ -283,10 +290,20 @@ void SDFReader::ParseAndAddBond(const String& line, int line_num,
String s_first_name=line.substr(0,3); String s_first_name=line.substr(0,3);
String s_second_name=line.substr(3,3); String s_second_name=line.substr(3,3);
String s_type=line.substr(6,3); String s_type=line.substr(6,3);
String first_name, second_name;
return std::make_tuple(s_first_name, s_second_name, s_type);
}
void SDFReader::AddBond(const bond_data& bond_tuple, int line_num, mol::EntityHandle& ent,
mol::XCSEditor& editor)
{
String s_first_name, s_second_name, s_type;
tie(s_first_name, s_second_name, s_type) = bond_tuple;
unsigned char type; unsigned char type;
mol::BondHandle bond; mol::BondHandle bond;
String first_name, second_name;
first_name=boost::trim_copy(s_first_name); first_name=boost::trim_copy(s_first_name);
second_name=boost::trim_copy(s_second_name); second_name=boost::trim_copy(s_second_name);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#ifndef OST_IO_SDF_READER_HH #ifndef OST_IO_SDF_READER_HH
#define OST_IO_SDF_READER_HH #define OST_IO_SDF_READER_HH
#include <tuple>
#include <boost/iostreams/filtering_stream.hpp> #include <boost/iostreams/filtering_stream.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <ost/mol/chain_handle.hh> #include <ost/mol/chain_handle.hh>
...@@ -30,6 +31,9 @@ ...@@ -30,6 +31,9 @@
namespace ost { namespace io { namespace ost { namespace io {
class DLLEXPORT_OST_IO SDFReader { class DLLEXPORT_OST_IO SDFReader {
public: public:
SDFReader(const String& filename); SDFReader(const String& filename);
...@@ -41,17 +45,22 @@ public: ...@@ -41,17 +45,22 @@ public:
void Import(mol::EntityHandle& ent); void Import(mol::EntityHandle& ent);
private: private:
typedef std::tuple<int, String, String, String, String, String> atom_data;
typedef std::tuple<String, String, String> bond_data;
void ClearState(const boost::filesystem::path& loc); void ClearState(const boost::filesystem::path& loc);
void NextMolecule(); void NextMolecule();
void ParseAndAddHeader(const String& line, int line_num, mol::EntityHandle& ent, void ParseHeader(const String& line, int line_num, mol::EntityHandle& ent,
mol::XCSEditor& editor); mol::XCSEditor& editor);
void ParseAndAddAtom(const String& line, int line_num, mol::EntityHandle& ent, void AddAtom(const atom_data& atom_tuple, int line_num, mol::EntityHandle& ent,
bool hetatm, mol::XCSEditor& editor); bool hetatm, mol::XCSEditor& editor);
atom_data ParseAtom(const String& line, int line_num);
void ParseAndAddBond(const String& line, int line_num, mol::EntityHandle& ent, void AddBond(const bond_data& bond_tuple, int line_num, mol::EntityHandle& ent,
mol::XCSEditor& editor); mol::XCSEditor& editor);
bond_data ParseBond(const String& line, int line_num);
String curr_chain_name_; String curr_chain_name_;
mol::ResidueKey curr_res_key_; mol::ResidueKey curr_res_key_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment