Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
8a41f6df
Commit
8a41f6df
authored
May 27, 2020
by
Charlles Abreu
Browse files
Better data encapsulation
parent
0b5d58d7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
19 deletions
+27
-19
wrappers/python/simtk/openmm/app/metadynamics.py
wrappers/python/simtk/openmm/app/metadynamics.py
+27
-19
No files found.
wrappers/python/simtk/openmm/app/metadynamics.py
View file @
8a41f6df
...
@@ -123,25 +123,29 @@ class Metadynamics(object):
...
@@ -123,25 +123,29 @@ class Metadynamics(object):
self
.
saveFrequency
=
saveFrequency
self
.
saveFrequency
=
saveFrequency
self
.
_id
=
np
.
random
.
randint
(
0x7FFFFFFF
)
self
.
_id
=
np
.
random
.
randint
(
0x7FFFFFFF
)
self
.
_saveIndex
=
0
self
.
_saveIndex
=
0
self
.
_expansion_variables
=
[]
for
v
in
variables
:
for
v
in
variables
:
v
.
_expanded
=
v
.
periodic
and
len
(
variables
)
>
1
expanded
=
v
.
periodic
and
len
(
variables
)
>
1
v
.
_extraWidth
=
min
(
gridExpansion
,
v
.
gridWidth
-
1
)
if
v
.
_expanded
else
0
extraWidth
=
min
(
gridExpansion
,
v
.
gridWidth
-
1
)
if
expanded
else
0
extraRange
=
v
.
_extraWidth
*
(
v
.
maxValue
-
v
.
minValue
)
/
(
v
.
gridWidth
-
1
)
extraRange
=
extraWidth
*
(
v
.
maxValue
-
v
.
minValue
)
/
(
v
.
gridWidth
-
1
)
v
.
_actualWidth
=
v
.
gridWidth
+
2
*
v
.
_extraWidth
actualWidth
=
v
.
gridWidth
+
2
*
extraWidth
v
.
_actualMin
=
v
.
minValue
-
extraRange
actualMin
=
v
.
minValue
-
extraRange
v
.
_actualMax
=
v
.
maxValue
+
extraRange
actualMax
=
v
.
maxValue
+
extraRange
v
.
_slice
=
slice
(
v
.
_extraWidth
,
v
.
gridWidth
+
v
.
_extraWidth
)
arraySlice
=
slice
(
extraWidth
,
v
.
gridWidth
+
extraWidth
)
self
.
_selfBias
=
np
.
zeros
(
tuple
(
v
.
_actualWidth
for
v
in
reversed
(
variables
)))
self
.
_expansion_variables
.
append
(
self
.
_totalBias
=
np
.
zeros
(
tuple
(
v
.
_actualWidth
for
v
in
reversed
(
variables
)))
_ExpansionData
(
expanded
,
extraWidth
,
actualWidth
,
actualMin
,
actualMax
,
arraySlice
),
)
self
.
_selfBias
=
np
.
zeros
(
tuple
(
v
.
actualWidth
for
v
in
reversed
(
self
.
_expansion_variables
)))
self
.
_totalBias
=
np
.
zeros
(
tuple
(
v
.
actualWidth
for
v
in
reversed
(
self
.
_expansion_variables
)))
self
.
_loadedBiases
=
{}
self
.
_loadedBiases
=
{}
self
.
_deltaT
=
temperature
*
(
biasFactor
-
1
)
self
.
_deltaT
=
temperature
*
(
biasFactor
-
1
)
varNames
=
[
'cv%d'
%
i
for
i
in
range
(
len
(
variables
))]
varNames
=
[
'cv%d'
%
i
for
i
in
range
(
len
(
variables
))]
self
.
_force
=
mm
.
CustomCVForce
(
'table(%s)'
%
', '
.
join
(
varNames
))
self
.
_force
=
mm
.
CustomCVForce
(
'table(%s)'
%
', '
.
join
(
varNames
))
for
name
,
var
in
zip
(
varNames
,
variables
):
for
name
,
var
in
zip
(
varNames
,
variables
):
self
.
_force
.
addCollectiveVariable
(
name
,
var
.
force
)
self
.
_force
.
addCollectiveVariable
(
name
,
var
.
force
)
widths
=
[
v
.
_
actualWidth
for
v
in
variables
]
widths
=
[
e
v
.
actualWidth
for
e
v
in
self
.
_expansion_
variables
]
mins
=
[
v
.
_
actualMin
for
v
in
variables
]
mins
=
[
e
v
.
actualMin
for
e
v
in
self
.
_expansion_
variables
]
maxs
=
[
v
.
_
actualMax
for
v
in
variables
]
maxs
=
[
e
v
.
actualMax
for
e
v
in
self
.
_expansion_
variables
]
if
len
(
variables
)
==
1
:
if
len
(
variables
)
==
1
:
self
.
_table
=
mm
.
Continuous1DFunction
(
self
.
_totalBias
.
flatten
(),
mins
[
0
],
maxs
[
0
],
variables
[
0
].
periodic
)
self
.
_table
=
mm
.
Continuous1DFunction
(
self
.
_totalBias
.
flatten
(),
mins
[
0
],
maxs
[
0
],
variables
[
0
].
periodic
)
elif
len
(
variables
)
==
2
:
elif
len
(
variables
)
==
2
:
...
@@ -194,7 +198,7 @@ class Metadynamics(object):
...
@@ -194,7 +198,7 @@ class Metadynamics(object):
if
len
(
self
.
variables
)
==
1
:
if
len
(
self
.
variables
)
==
1
:
return
f
return
f
else
:
else
:
s
=
[
v
.
_
slice
for
v
in
self
.
variables
]
s
=
[
e
v
.
slice
for
e
v
in
self
.
_expansion_
variables
]
return
f
[
s
[
1
],
s
[
0
]]
if
len
(
self
.
variables
)
==
2
else
f
[
s
[
2
],
s
[
1
],
s
[
0
]]
return
f
[
s
[
1
],
s
[
0
]]
if
len
(
self
.
variables
)
==
2
else
f
[
s
[
2
],
s
[
1
],
s
[
0
]]
def
getCollectiveVariables
(
self
,
simulation
):
def
getCollectiveVariables
(
self
,
simulation
):
...
@@ -206,7 +210,7 @@ class Metadynamics(object):
...
@@ -206,7 +210,7 @@ class Metadynamics(object):
# Compute a Gaussian along each axis.
# Compute a Gaussian along each axis.
axisGaussians
=
[]
axisGaussians
=
[]
for
i
,
v
in
enumerate
(
self
.
variables
):
for
i
,
(
v
,
ev
)
in
enumerate
(
zip
(
self
.
variables
,
self
.
_expansion_variables
)
):
x
=
(
position
[
i
]
-
v
.
minValue
)
/
(
v
.
maxValue
-
v
.
minValue
)
x
=
(
position
[
i
]
-
v
.
minValue
)
/
(
v
.
maxValue
-
v
.
minValue
)
if
v
.
periodic
:
if
v
.
periodic
:
x
=
x
%
1.0
x
=
x
%
1.0
...
@@ -214,8 +218,8 @@ class Metadynamics(object):
...
@@ -214,8 +218,8 @@ class Metadynamics(object):
if
v
.
periodic
:
if
v
.
periodic
:
dist
=
np
.
min
(
np
.
array
([
dist
,
np
.
abs
(
dist
-
1
)]),
axis
=
0
)
dist
=
np
.
min
(
np
.
array
([
dist
,
np
.
abs
(
dist
-
1
)]),
axis
=
0
)
values
=
np
.
exp
(
-
0.5
*
dist
*
dist
/
v
.
_scaledVariance
)
values
=
np
.
exp
(
-
0.5
*
dist
*
dist
/
v
.
_scaledVariance
)
if
v
.
_
expanded
:
if
e
v
.
expanded
:
n
=
v
.
_
extraWidth
+
1
n
=
e
v
.
extraWidth
+
1
values
=
np
.
hstack
((
values
[
-
n
:
-
1
],
values
,
values
[
1
:
n
]))
values
=
np
.
hstack
((
values
[
-
n
:
-
1
],
values
,
values
[
1
:
n
]))
axisGaussians
.
append
(
values
)
axisGaussians
.
append
(
values
)
...
@@ -231,9 +235,9 @@ class Metadynamics(object):
...
@@ -231,9 +235,9 @@ class Metadynamics(object):
height
=
height
.
value_in_unit
(
unit
.
kilojoules_per_mole
)
height
=
height
.
value_in_unit
(
unit
.
kilojoules_per_mole
)
self
.
_selfBias
+=
height
*
gaussian
self
.
_selfBias
+=
height
*
gaussian
self
.
_totalBias
+=
height
*
gaussian
self
.
_totalBias
+=
height
*
gaussian
widths
=
[
v
.
_
actualWidth
for
v
in
self
.
variables
]
widths
=
[
e
v
.
actualWidth
for
e
v
in
self
.
_expansion_
variables
]
mins
=
[
v
.
_
actualMin
for
v
in
self
.
variables
]
mins
=
[
e
v
.
actualMin
for
e
v
in
self
.
_expansion_
variables
]
maxs
=
[
v
.
_
actualMax
for
v
in
self
.
variables
]
maxs
=
[
e
v
.
actualMax
for
e
v
in
self
.
_expansion_
variables
]
if
len
(
self
.
variables
)
==
1
:
if
len
(
self
.
variables
)
==
1
:
self
.
_totalBias
[
-
1
]
=
self
.
_totalBias
[
0
]
self
.
_totalBias
[
-
1
]
=
self
.
_totalBias
[
0
]
self
.
_table
.
setFunctionParameters
(
self
.
_totalBias
.
flatten
(),
mins
[
0
],
maxs
[
0
])
self
.
_table
.
setFunctionParameters
(
self
.
_totalBias
.
flatten
(),
mins
[
0
],
maxs
[
0
])
...
@@ -329,3 +333,7 @@ class BiasVariable(object):
...
@@ -329,3 +333,7 @@ class BiasVariable(object):
return
quantity
return
quantity
_LoadedBias
=
namedtuple
(
'LoadedBias'
,
[
'id'
,
'index'
,
'bias'
])
_LoadedBias
=
namedtuple
(
'LoadedBias'
,
[
'id'
,
'index'
,
'bias'
])
_ExpansionData
=
namedtuple
(
'ExpansionData'
,
[
'expanded'
,
'extraWidth'
,
'actualWidth'
,
'actualMin'
,
'actualMax'
,
'slice'
],
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment