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
8cee0b7a
Unverified
Commit
8cee0b7a
authored
1 year ago
by
Xavier Robin
Browse files
Options
Downloads
Patches
Plain Diff
fix: write charge in SDF writer
parent
7c3137b9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/io/src/mol/sdf_writer.cc
+24
-1
24 additions, 1 deletion
modules/io/src/mol/sdf_writer.cc
modules/io/tests/test_io_sdf.py
+22
-0
22 additions, 0 deletions
modules/io/tests/test_io_sdf.py
with
46 additions
and
1 deletion
modules/io/src/mol/sdf_writer.cc
+
24
−
1
View file @
8cee0b7a
...
...
@@ -50,7 +50,12 @@ namespace {
<<
format
(
"%10.4f"
)
%
atom
.
GetPos
()[
1
]
<<
format
(
"%10.4f "
)
%
atom
.
GetPos
()[
2
]
<<
format
(
"%-3s"
)
%
SDFAtomWriter
::
FormatEle
(
atom
.
GetElement
())
<<
" 0 0 0 0 0 0"
<<
" 0"
// Mass difference
<<
format
(
"%-3s"
)
%
SDFAtomWriter
::
FormatCharge
(
atom
.
GetCharge
())
// Charge
<<
" 0"
// Atom stereo parity
<<
" 0"
// Hydrogen count + 1
<<
" 0"
// Stereo care box
<<
" 0"
// Valence
<<
std
::
endl
;
return
true
;
}
...
...
@@ -66,6 +71,24 @@ namespace {
}
return
return_ele
;
}
static
String
FormatCharge
(
const
Real
&
chg
)
{
// Format charge according to https://doi.org/10.1021/ci00007a012
// 0 = uncharged or value other than these, 1 = +3, 2 = +2, 3 = +1,
// 4 doublet (A), 5 = -1, 6 = -2, 7 = -3
// Doublet means radical. This function would never return 4.
if
(
chg
==
0
)
{
return
" 0"
;
}
else
if
(
abs
(
chg
)
>
3
)
{
String
msg
=
"SDF format only supports charges from -3 to +3, not %g"
;
throw
IOException
(
str
(
format
(
msg
)
%
chg
));
}
else
{
Real
chg_sdf
=
4
-
chg
;
return
str
(
format
(
"%3.0f"
)
%
chg_sdf
);
}
}
private
:
std
::
ostream
&
ostr_
;
std
::
map
<
long
,
int
>&
atom_indices_
;
...
...
This diff is collapsed.
Click to expand it.
modules/io/tests/test_io_sdf.py
+
22
−
0
View file @
8cee0b7a
...
...
@@ -16,6 +16,28 @@ class TestSDF(unittest.TestCase):
ent
=
io
.
LoadSDF
(
'
testfiles/sdf/6d5w_rank1_crlf.sdf.gz
'
)
self
.
assertEqual
(
len
(
ent
.
atoms
),
21
)
self
.
assertEqual
(
len
(
ent
.
bonds
),
24
)
def
test_Charge
(
self
):
ent
=
io
.
LoadSDF
(
'
testfiles/sdf/simple.sdf
'
)
self
.
assertEqual
(
ent
.
FindAtom
(
"
00001_Simple Ligand
"
,
1
,
"
6
"
).
charge
,
0
)
# Write and read charges properly
for
chg
in
range
(
-
3
,
4
):
ent
.
FindAtom
(
"
00001_Simple Ligand
"
,
1
,
"
6
"
).
charge
=
chg
sdf_str
=
io
.
EntityToSDFStr
(
ent
)
ent
=
io
.
SDFStrToEntity
(
sdf_str
)
self
.
assertEqual
(
ent
.
FindAtom
(
"
00001_Simple Ligand
"
,
1
,
"
6
"
).
charge
,
chg
)
# Only -3 to +3 is supported
# If M CHG is implemented the following tests can be removed
with
self
.
assertRaises
(
Exception
):
ent
.
FindAtom
(
"
00001_Simple Ligand
"
,
1
,
"
6
"
).
charge
=
4
io
.
EntityToSDFStr
(
ent
)
with
self
.
assertRaises
(
Exception
):
ent
.
FindAtom
(
"
00001_Simple Ligand
"
,
1
,
"
6
"
).
charge
=
-
4
io
.
EntityToSDFStr
(
ent
)
if
__name__
==
'
__main__
'
:
from
ost
import
testutils
...
...
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