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
ac1e0c09
Commit
ac1e0c09
authored
13 years ago
by
Tobias Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
modified sdf writer to ensure correct bond order
parent
c915dd22
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/io/src/mol/sdf_writer.cc
+54
-15
54 additions, 15 deletions
modules/io/src/mol/sdf_writer.cc
with
54 additions
and
15 deletions
modules/io/src/mol/sdf_writer.cc
+
54
−
15
View file @
ac1e0c09
...
...
@@ -27,6 +27,7 @@
#include
<ost/mol/chain_view.hh>
#include
<ost/mol/bond_handle.hh>
#include
<boost/regex.hpp>
#include
<boost/bind.hpp>
namespace
ost
{
namespace
io
{
...
...
@@ -38,7 +39,7 @@ namespace {
public:
SDFAtomWriter
(
std
::
ostream
&
ostream
,
std
::
map
<
long
,
int
>&
atom_indices
)
:
ostr_
(
ostream
),
atom_indices_
(
atom_indices
),
counter_
(
0
)
{
atom_indices_
.
clear
();
atom_indices_
.
clear
();
}
private
:
public
:
...
...
@@ -60,23 +61,61 @@ namespace {
class
SDFBondWriter
:
public
mol
::
EntityViewVisitor
{
public:
SDFBondWriter
(
std
::
ostream
&
ostream
,
std
::
map
<
long
,
int
>&
atom_indices
)
SDFBondWriter
(
std
::
ostream
&
ostream
,
const
std
::
map
<
long
,
int
>&
atom_indices
)
:
ostr_
(
ostream
),
atom_indices_
(
atom_indices
),
counter_
(
0
)
{
}
private
:
// compare two atoms according to their indices (used for sorting)
bool
CompareAtomIdx
(
const
mol
::
AtomView
&
first
,
const
mol
::
AtomView
&
second
)
{
std
::
map
<
long
,
int
>::
const_iterator
aidx_first
(
atom_indices_
.
find
(
first
.
GetHashCode
()));
std
::
map
<
long
,
int
>::
const_iterator
aidx_second
(
atom_indices_
.
find
(
second
.
GetHashCode
()));
if
(
aidx_first
==
atom_indices_
.
end
()
||
aidx_second
==
atom_indices_
.
end
())
{
throw
IOException
(
"Cannot write bond: atom idx not found for sorting"
);
}
return
(
aidx_first
->
second
<
aidx_second
->
second
);
}
public
:
virtual
bool
VisitAtom
(
const
mol
::
AtomView
&
atom
)
{
counter_
++
;
++
counter_
;
// current atom index
// get all neighboring atoms and sort them according to their atom index
mol
::
AtomViewList
atoms
=
atom
.
GetBondPartners
();
mol
::
AtomViewList
::
iterator
atom_iter
=
atoms
.
begin
();
for
(;
atom_iter
!=
atoms
.
end
();
++
atom_iter
)
{
int
atom_index
=
atom_indices_
.
find
((
*
atom_iter
).
GetHashCode
())
->
second
;
if
(
atom_index
>
counter_
)
{
int
type
=
1
;
mol
::
BondHandle
bond
=
atom
.
GetHandle
().
FindBondToAtom
(
atom_iter
->
GetHandle
());
if
(
bond
.
IsValid
())
type
=
bond
.
GetBondOrder
();
std
::
sort
(
atoms
.
begin
(),
atoms
.
end
(),
bind
(
&
SDFBondWriter
::
CompareAtomIdx
,
this
,
_1
,
_2
));
// iterate all neighboring atoms and print bonds to all atoms with index
// larger than current atom index
for
(
mol
::
AtomViewList
::
iterator
atom_iter
=
atoms
.
begin
();
atom_iter
!=
atoms
.
end
();
++
atom_iter
)
{
std
::
map
<
long
,
int
>::
const_iterator
aidx
(
atom_indices_
.
find
((
*
atom_iter
).
GetHashCode
()));
// check if index was found
if
(
aidx
==
atom_indices_
.
end
())
{
throw
IOException
(
"Cannot write bond between "
+
atom
.
GetQualifiedName
()
+
" and "
+
atom_iter
->
GetQualifiedName
()
+
": atom index not found"
);
}
// only print bonds to atoms with larger index than current index
if
(
aidx
->
second
>
counter_
)
{
mol
::
BondHandle
bond
(
atom
.
GetHandle
().
FindBondToAtom
(
atom_iter
->
GetHandle
()));
if
(
!
bond
.
IsValid
())
{
throw
IOException
(
"Bond is invalid between "
+
atom
.
GetQualifiedName
()
+
" and "
+
atom_iter
->
GetQualifiedName
());
}
int
type
=
bond
.
GetBondOrder
();
ostr_
<<
format
(
"%3i"
)
%
counter_
<<
format
(
"%3i"
)
%
a
tom_index
<<
format
(
"%3i"
)
%
a
idx
->
second
<<
format
(
"%3i"
)
%
type
<<
" 0 0 0"
<<
std
::
endl
;
...
...
@@ -87,17 +126,17 @@ namespace {
private
:
std
::
ostream
&
ostr_
;
std
::
map
<
long
,
int
>&
atom_indices_
;
const
std
::
map
<
long
,
int
>&
atom_indices_
;
int
counter_
;
};
}
SDFWriter
::
SDFWriter
(
std
::
ostream
&
ostream
)
:
outfile_
(),
ostr_
(
ostream
),
counter_
(
0
)
{
:
outfile_
(),
ostr_
(
ostream
),
counter_
(
0
)
,
atom_indices_
()
{
}
SDFWriter
::
SDFWriter
(
const
String
&
filename
)
:
outfile_
(
filename
.
c_str
()),
ostr_
(
outfile_
),
counter_
(
0
)
{
:
outfile_
(
filename
.
c_str
()),
ostr_
(
outfile_
),
counter_
(
0
)
,
atom_indices_
()
{
}
SDFWriter
::
SDFWriter
(
const
boost
::
filesystem
::
path
&
filename
)
:
...
...
@@ -106,7 +145,7 @@ SDFWriter::SDFWriter(const boost::filesystem::path& filename):
#else
outfile_
(
filename
.
file_string
().
c_str
()),
#endif
ostr_
(
outfile_
),
counter_
(
0
)
{
ostr_
(
outfile_
),
counter_
(
0
)
,
atom_indices_
()
{
}
void
SDFWriter
::
Write
(
const
mol
::
EntityView
&
ent
)
{
...
...
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