Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pycgtool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
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
James Graham
pycgtool
Commits
6bb0458b
Commit
6bb0458b
authored
8 years ago
by
James Graham
Browse files
Options
Downloads
Patches
Plain Diff
Use float tolerance comparison in itp test
Slight differences in values if numba is not present
parent
d4fabd07
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pycgtool/bondset.py
+12
-13
12 additions, 13 deletions
pycgtool/bondset.py
pycgtool/util.py
+45
-0
45 additions, 0 deletions
pycgtool/util.py
test/test_bondset.py
+2
-2
2 additions, 2 deletions
test/test_bondset.py
with
59 additions
and
15 deletions
pycgtool/bondset.py
+
12
−
13
View file @
6bb0458b
...
...
@@ -345,30 +345,29 @@ class BondSet:
bond
.
boltzmann_invert
(
temp
=
self
.
_temperature
,
angle_default_fc
=
self
.
_angle_default_fc
)
def
dump_values
(
self
,
target_number
=
10000
0
):
def
dump_values
(
self
,
target_number
=
10000
):
"""
Output measured bond values to files for length, angles and dihedrals.
:param target_number: Approx number of sample measurements to output. If None, all samples will be output
"""
def
write_bonds_to_file
(
bonds
,
filename
):
with
open
(
filename
,
"
w
"
)
as
f
:
for
row
in
transpose_and_sample
((
bond
.
values
for
bond
in
bonds
),
n
=
target_number
):
print
((
len
(
row
)
*
"
{:12.5f}
"
).
format
(
*
row
),
file
=
f
)
for
mol
in
self
.
_molecules
:
if
mol
==
"
SOL
"
:
continue
with
open
(
"
{0}_length.dat
"
.
format
(
mol
),
"
w
"
)
as
f
:
bonds
=
self
.
get_bond_lengths
(
mol
,
with_constr
=
True
)
for
row
in
transpose_and_sample
((
bond
.
values
for
bond
in
bonds
),
n
=
target_number
):
print
((
len
(
row
)
*
"
{:12.5f}
"
).
format
(
*
row
),
file
=
f
)
bonds
=
self
.
get_bond_lengths
(
mol
,
with_constr
=
True
)
write_bonds_to_file
(
bonds
,
"
{0}_length.dat
"
.
format
(
mol
))
with
open
(
"
{0}_angle.dat
"
.
format
(
mol
),
"
w
"
)
as
f
:
bonds
=
self
.
get_bond_angles
(
mol
)
for
row
in
transpose_and_sample
((
bond
.
values
for
bond
in
bonds
),
n
=
target_number
):
print
((
len
(
row
)
*
"
{:12.5f}
"
).
format
(
*
row
),
file
=
f
)
bonds
=
self
.
get_bond_angles
(
mol
)
write_bonds_to_file
(
bonds
,
"
{0}_angle.dat
"
.
format
(
mol
))
with
open
(
"
{0}_dihedral.dat
"
.
format
(
mol
),
"
w
"
)
as
f
:
bonds
=
self
.
get_bond_dihedrals
(
mol
)
for
row
in
transpose_and_sample
((
bond
.
values
for
bond
in
bonds
),
n
=
target_number
):
print
((
len
(
row
)
*
"
{:12.5f}
"
).
format
(
*
row
),
file
=
f
)
bonds
=
self
.
get_bond_dihedrals
(
mol
)
write_bonds_to_file
(
bonds
,
"
{0}_dihedral.dat
"
.
format
(
mol
))
def
__len__
(
self
):
return
len
(
self
.
_molecules
)
...
...
This diff is collapsed.
Click to expand it.
pycgtool/util.py
+
45
−
0
View file @
6bb0458b
...
...
@@ -6,6 +6,7 @@ import os
import
itertools
import
random
import
math
import
filecmp
import
numpy
as
np
np
.
seterr
(
all
=
"
raise
"
)
...
...
@@ -307,3 +308,47 @@ def gaussian(xs, mean=0, sdev=1, amplitude=1):
top_bit
=
(
x
-
mean
)
*
(
x
-
mean
)
/
(
2
*
sdev
*
sdev
)
return
prefactor
*
np
.
exp
(
-
top_bit
)
return
map
(
gaussian_single
,
xs
)
def
cmp_whitespace_float
(
ref_filename
,
test_filename
,
float_rel_error
=
0.01
):
"""
Compare two files ignoring spacing on a line and using a tolerance on floats
:param ref_filename: Name of reference file
:param test_filename: Name of test file
:param float_rel_error: Acceptable relative error on floating point numbers
:return: True if files are the same, else False
"""
def
float_or_string
(
string
):
try
:
int
(
string
)
return
string
except
ValueError
:
try
:
return
float
(
string
)
except
ValueError
:
return
string
if
filecmp
.
cmp
(
ref_filename
,
test_filename
):
return
True
with
open
(
ref_filename
)
as
ref_file
,
open
(
test_filename
)
as
test_file
:
for
ref_line
,
test_line
in
itertools
.
zip_longest
(
ref_file
,
test_file
):
if
ref_line
is
None
or
test_line
is
None
:
return
False
if
ref_line
==
test_line
:
continue
ref_toks
=
ref_line
.
split
()
test_toks
=
test_line
.
split
()
if
len
(
ref_toks
)
!=
len
(
test_toks
):
return
False
for
ref_tok
,
test_tok
in
zip
(
map
(
float_or_string
,
ref_toks
),
map
(
float_or_string
,
test_toks
)):
if
ref_tok
!=
test_tok
:
if
float
==
type
(
ref_tok
)
and
float
==
type
(
test_tok
):
if
abs
(
ref_tok
-
test_tok
)
>
ref_tok
*
float_rel_error
:
return
False
else
:
return
False
return
True
This diff is collapsed.
Click to expand it.
test/test_bondset.py
+
2
−
2
View file @
6bb0458b
import
unittest
import
filecmp
from
pycgtool.bondset
import
BondSet
from
pycgtool.frame
import
Frame
from
pycgtool.mapping
import
Mapping
from
pycgtool.util
import
cmp_whitespace_float
class
DummyOptions
:
...
...
@@ -118,4 +118,4 @@ class BondSetTest(unittest.TestCase):
measure
.
boltzmann_invert
()
measure
.
write_itp
(
"
sugar_out.itp
"
,
mapping
,
exclude
=
{
"
SOL
"
})
self
.
assertTrue
(
filecmp
.
cmp
(
"
sugar_out.itp
"
,
"
test/data/sugar_out.itp
"
))
self
.
assertTrue
(
cmp_whitespace_float
(
"
sugar_out.itp
"
,
"
test/data/sugar_out.itp
"
,
float_rel_error
=
0.001
))
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