Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schwede
openstructure
Commits
1cd69a8b
Verified
Commit
1cd69a8b
authored
1 year ago
by
Xavier Robin
Browse files
Options
Downloads
Patches
Plain Diff
refactor: separate parse and add
parent
08991a8e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/io/src/mol/sdf_reader.cc
+27
-10
27 additions, 10 deletions
modules/io/src/mol/sdf_reader.cc
modules/io/src/mol/sdf_reader.hh
+13
-4
13 additions, 4 deletions
modules/io/src/mol/sdf_reader.hh
with
40 additions
and
14 deletions
modules/io/src/mol/sdf_reader.cc
+
27
−
10
View file @
1cd69a8b
...
...
@@ -71,11 +71,11 @@ void SDFReader::Import(mol::EntityHandle& ent)
}
if
(
line_num
<=
4
)
{
Parse
AndAdd
Header
(
line
,
line_num
,
ent
,
editor
);
ParseHeader
(
line
,
line_num
,
ent
,
editor
);
}
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
)
{
ParseAndAddBond
(
line
,
line_num
,
ent
,
editor
);
AddBond
(
ParseBond
(
line
,
line_num
)
,
line_num
,
ent
,
editor
);
}
else
if
(
boost
::
iequals
(
line
.
substr
(
0
,
2
),
"> "
))
{
// parse data items
int
data_header_start
=
line
.
find
(
'<'
);
...
...
@@ -129,7 +129,7 @@ void SDFReader::NextMolecule()
curr_chain_
=
ost
::
mol
::
ChainHandle
();
}
void
SDFReader
::
Parse
AndAdd
Header
(
const
String
&
line
,
int
line_num
,
void
SDFReader
::
ParseHeader
(
const
String
&
line
,
int
line_num
,
mol
::
EntityHandle
&
ent
,
mol
::
XCSEditor
&
editor
)
{
LOG_TRACE
(
"line: ["
<<
line
<<
"]"
);
...
...
@@ -190,9 +190,7 @@ void SDFReader::ParseAndAddHeader(const String& line, int line_num,
}
}
void
SDFReader
::
ParseAndAddAtom
(
const
String
&
line
,
int
line_num
,
mol
::
EntityHandle
&
ent
,
bool
hetatm
,
mol
::
XCSEditor
&
editor
)
SDFReader
::
atom_data
SDFReader
::
ParseAtom
(
const
String
&
line
,
int
line_num
)
{
LOG_TRACE
(
"line: ["
<<
line
<<
"]"
);
...
...
@@ -215,6 +213,16 @@ void SDFReader::ParseAndAddAtom(const String& line, int line_num,
String
s_ele
=
line
.
substr
(
31
,
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
;
try
{
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,
}
void
SDFReader
::
ParseAndAddBond
(
const
String
&
line
,
int
line_num
,
mol
::
EntityHandle
&
ent
,
mol
::
XCSEditor
&
editor
)
SDFReader
::
bond_data
SDFReader
::
ParseBond
(
const
String
&
line
,
int
line_num
)
{
LOG_TRACE
(
"line: ["
<<
line
<<
"]"
);
...
...
@@ -283,10 +290,20 @@ void SDFReader::ParseAndAddBond(const String& line, int line_num,
String
s_first_name
=
line
.
substr
(
0
,
3
);
String
s_second_name
=
line
.
substr
(
3
,
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
;
mol
::
BondHandle
bond
;
String
first_name
,
second_name
;
first_name
=
boost
::
trim_copy
(
s_first_name
);
second_name
=
boost
::
trim_copy
(
s_second_name
);
...
...
This diff is collapsed.
Click to expand it.
modules/io/src/mol/sdf_reader.hh
+
13
−
4
View file @
1cd69a8b
...
...
@@ -22,6 +22,7 @@
#ifndef OST_IO_SDF_READER_HH
#define OST_IO_SDF_READER_HH
#include
<tuple>
#include
<boost/iostreams/filtering_stream.hpp>
#include
<boost/filesystem/fstream.hpp>
#include
<ost/mol/chain_handle.hh>
...
...
@@ -30,6 +31,9 @@
namespace
ost
{
namespace
io
{
class
DLLEXPORT_OST_IO
SDFReader
{
public:
SDFReader
(
const
String
&
filename
);
...
...
@@ -41,17 +45,22 @@ public:
void
Import
(
mol
::
EntityHandle
&
ent
);
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
NextMolecule
();
void
Parse
AndAdd
Header
(
const
String
&
line
,
int
line_num
,
mol
::
EntityHandle
&
ent
,
void
ParseHeader
(
const
String
&
line
,
int
line_num
,
mol
::
EntityHandle
&
ent
,
mol
::
XCSEditor
&
editor
);
void
ParseAndAddAtom
(
const
String
&
line
,
int
line_num
,
mol
::
EntityHandle
&
ent
,
bool
hetatm
,
mol
::
XCSEditor
&
editor
);
void
AddAtom
(
const
atom_data
&
atom_tuple
,
int
line_num
,
mol
::
EntityHandle
&
ent
,
bool
hetatm
,
mol
::
XCSEditor
&
editor
);
atom_data
ParseAtom
(
const
String
&
line
,
int
line_num
);
void
ParseAnd
AddBond
(
const
String
&
lin
e
,
int
line_num
,
mol
::
EntityHandle
&
ent
,
void
AddBond
(
const
bond_data
&
bond_tupl
e
,
int
line_num
,
mol
::
EntityHandle
&
ent
,
mol
::
XCSEditor
&
editor
);
bond_data
ParseBond
(
const
String
&
line
,
int
line_num
);
String
curr_chain_name_
;
mol
::
ResidueKey
curr_res_key_
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment