Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tbgl
tools
mrdna
Commits
9f55d328
Commit
9f55d328
authored
Jun 24, 2020
by
cmaffeo2
Browse files
Initial commit of bondAngle (one angle, two bonds)
parent
7ffdf594
Changes
2
Hide whitespace changes
Inline
Side-by-side
mrdna/arbdmodel/__init__.py
View file @
9f55d328
...
@@ -71,6 +71,7 @@ class Parent():
...
@@ -71,6 +71,7 @@ class Parent():
self
.
dihedrals
=
[]
self
.
dihedrals
=
[]
self
.
impropers
=
[]
self
.
impropers
=
[]
self
.
exclusions
=
[]
self
.
exclusions
=
[]
self
.
bond_angles
=
[]
self
.
rigid
=
False
self
.
rigid
=
False
...
@@ -148,6 +149,13 @@ class Parent():
...
@@ -148,6 +149,13 @@ class Parent():
# for b in (i,j): assert(b in beads)
# for b in (i,j): assert(b in beads)
self
.
exclusions
.
append
(
(
i
,
j
)
)
self
.
exclusions
.
append
(
(
i
,
j
)
)
def
add_bond_angle
(
self
,
i
,
j
,
k
,
bond_angle
,
exclude
=
False
):
assert
(
len
(
set
((
i
,
j
,
k
)))
==
3
)
## TODO: how to handle duplicating and cloning bonds
# beads = [b for b in self]
# for b in (i,j): assert(b in beads)
self
.
bond_angles
.
append
(
(
i
,
j
,
k
,
bond_angle
)
)
def
get_restraints
(
self
):
def
get_restraints
(
self
):
ret
=
[]
ret
=
[]
for
c
in
self
.
children
:
for
c
in
self
.
children
:
...
@@ -200,6 +208,27 @@ class Parent():
...
@@ -200,6 +208,27 @@ class Parent():
else
:
else
:
return
ret
return
ret
def
get_bond_angles
(
self
):
ret
=
self
.
bond_angles
for
c
in
self
.
children
:
if
isinstance
(
c
,
Parent
):
ret
.
extend
(
c
.
get_bond_angles
()
)
if
self
.
remove_duplicate_bonded_terms
:
return
list
(
set
(
ret
))
else
:
return
ret
def
_get_bond_potentials
(
self
):
bonds
=
[
b
for
i
,
j
,
b
,
ex
in
self
.
get_bonds
()]
bondangles1
=
[
b
[
1
]
for
i
,
j
,
k
,
b
in
self
.
get_bond_angles
()]
bondangles2
=
[
b
[
2
]
for
i
,
j
,
k
,
b
in
self
.
get_bond_angles
()]
return
list
(
set
(
bonds
+
bondangles1
+
bondangles2
))
def
_get_angle_potentials
(
self
):
angles
=
[
b
for
i
,
j
,
k
,
b
in
self
.
get_angles
()]
bondangles
=
[
b
[
0
]
for
i
,
j
,
k
,
b
in
self
.
get_bond_angles
()]
return
list
(
set
(
angles
+
bondangles
))
## Removed because prohibitively slow
## Removed because prohibitively slow
# def remove_duplicate_terms(self):
# def remove_duplicate_terms(self):
# for key in "bonds angles dihedrals impropers exclusions".split():
# for key in "bonds angles dihedrals impropers exclusions".split():
...
@@ -863,6 +892,7 @@ class ArbdModel(PdbModel):
...
@@ -863,6 +892,7 @@ class ArbdModel(PdbModel):
self
.
_angle_filename
=
"%s/%s.angles.txt"
%
(
d
,
prefix
)
self
.
_angle_filename
=
"%s/%s.angles.txt"
%
(
d
,
prefix
)
self
.
_dihedral_filename
=
"%s/%s.dihedrals.txt"
%
(
d
,
prefix
)
self
.
_dihedral_filename
=
"%s/%s.dihedrals.txt"
%
(
d
,
prefix
)
self
.
_exclusion_filename
=
"%s/%s.exculsions.txt"
%
(
d
,
prefix
)
self
.
_exclusion_filename
=
"%s/%s.exculsions.txt"
%
(
d
,
prefix
)
self
.
_bond_angle_filename
=
"%s/%s.bondangles.txt"
%
(
d
,
prefix
)
# self._writeArbdCoordFile( prefix + ".coord.txt" )
# self._writeArbdCoordFile( prefix + ".coord.txt" )
self
.
_writeArbdParticleFile
(
prefix
+
".particles.txt"
)
self
.
_writeArbdParticleFile
(
prefix
+
".particles.txt"
)
...
@@ -871,6 +901,7 @@ class ArbdModel(PdbModel):
...
@@ -871,6 +901,7 @@ class ArbdModel(PdbModel):
self
.
_writeArbdAngleFile
()
self
.
_writeArbdAngleFile
()
self
.
_writeArbdDihedralFile
()
self
.
_writeArbdDihedralFile
()
self
.
_writeArbdExclusionFile
()
self
.
_writeArbdExclusionFile
()
self
.
_writeArbdBondAngleFile
()
self
.
_writeArbdPotentialFiles
(
prefix
,
directory
=
d
)
self
.
_writeArbdPotentialFiles
(
prefix
,
directory
=
d
)
self
.
_writeArbdConf
(
prefix
,
numSteps
=
numSteps
,
outputPeriod
=
outputPeriod
,
restart_file
=
restart_file
)
self
.
_writeArbdConf
(
prefix
,
numSteps
=
numSteps
,
outputPeriod
=
outputPeriod
,
restart_file
=
restart_file
)
...
@@ -1066,13 +1097,13 @@ tabulatedPotential 1
...
@@ -1066,13 +1097,13 @@ tabulatedPotential 1
angles
=
self
.
get_angles
()
angles
=
self
.
get_angles
()
dihedrals
=
self
.
get_dihedrals
()
dihedrals
=
self
.
get_dihedrals
()
exclusions
=
self
.
get_exclusions
()
exclusions
=
self
.
get_exclusions
()
bond_angles
=
self
.
get_bond_angles
()
if
len
(
bonds
)
>
0
:
if
len
(
bonds
)
>
0
:
for
b
in
list
(
set
([
b
for
i
,
j
,
b
,
ex
in
bonds
])
):
for
b
in
self
.
_get_bond_potentials
(
):
fh
.
write
(
"tabulatedBondFile %s
\n
"
%
b
)
fh
.
write
(
"tabulatedBondFile %s
\n
"
%
b
)
if
len
(
angles
)
>
0
:
if
len
(
angles
)
>
0
:
for
b
in
list
(
set
([
b
for
i
,
j
,
k
,
b
in
angles
])
):
for
b
in
self
.
_get_angle_potentials
(
):
fh
.
write
(
"tabulatedAngleFile %s
\n
"
%
b
)
fh
.
write
(
"tabulatedAngleFile %s
\n
"
%
b
)
if
len
(
dihedrals
)
>
0
:
if
len
(
dihedrals
)
>
0
:
...
@@ -1089,6 +1120,8 @@ tabulatedPotential 1
...
@@ -1089,6 +1120,8 @@ tabulatedPotential 1
fh
.
write
(
"inputDihedrals %s
\n
"
%
self
.
_dihedral_filename
)
fh
.
write
(
"inputDihedrals %s
\n
"
%
self
.
_dihedral_filename
)
if
len
(
exclusions
)
>
0
:
if
len
(
exclusions
)
>
0
:
fh
.
write
(
"inputExcludes %s
\n
"
%
self
.
_exclusion_filename
)
fh
.
write
(
"inputExcludes %s
\n
"
%
self
.
_exclusion_filename
)
if
len
(
bond_angles
)
>
0
:
fh
.
write
(
"inputBondAngles %s
\n
"
%
self
.
_bond_angle_filename
)
write_null_dx
=
False
write_null_dx
=
False
for
pt
,
num
in
self
.
getParticleTypesAndCounts
():
for
pt
,
num
in
self
.
getParticleTypesAndCounts
():
...
@@ -1164,7 +1197,7 @@ component "data" value 3
...
@@ -1164,7 +1197,7 @@ component "data" value 3
fh
.
write
(
"RESTRAINT %d %f %f %f %f
\n
"
%
tuple
(
item
))
fh
.
write
(
"RESTRAINT %d %f %f %f %f
\n
"
%
tuple
(
item
))
def
_writeArbdBondFile
(
self
):
def
_writeArbdBondFile
(
self
):
for
b
in
list
(
set
(
[
b
for
i
,
j
,
b
,
ex
in
self
.
get_bond
s
()]
)
):
for
b
in
self
.
_
get_bond
_potentials
(
):
if
type
(
b
)
is
not
str
and
not
isinstance
(
b
,
Path
):
if
type
(
b
)
is
not
str
and
not
isinstance
(
b
,
Path
):
b
.
write_file
()
b
.
write_file
()
...
@@ -1177,7 +1210,7 @@ component "data" value 3
...
@@ -1177,7 +1210,7 @@ component "data" value 3
fh
.
write
(
"BOND ADD %d %d %s
\n
"
%
item
)
fh
.
write
(
"BOND ADD %d %d %s
\n
"
%
item
)
def
_writeArbdAngleFile
(
self
):
def
_writeArbdAngleFile
(
self
):
for
b
in
list
(
set
(
[
b
for
i
,
j
,
k
,
b
in
self
.
get_angle
s
()]
)
):
for
b
in
self
.
_
get_angle
_potentials
(
):
if
type
(
b
)
is
not
str
and
not
isinstance
(
b
,
Path
):
if
type
(
b
)
is
not
str
and
not
isinstance
(
b
,
Path
):
b
.
write_file
()
b
.
write_file
()
...
@@ -1202,6 +1235,13 @@ component "data" value 3
...
@@ -1202,6 +1235,13 @@ component "data" value 3
item
=
tuple
(
int
(
p
.
idx
)
for
p
in
ex
)
item
=
tuple
(
int
(
p
.
idx
)
for
p
in
ex
)
fh
.
write
(
"EXCLUDE %d %d
\n
"
%
item
)
fh
.
write
(
"EXCLUDE %d %d
\n
"
%
item
)
def
_writeArbdBondAngleFile
(
self
):
if
len
(
self
.
bond_angles
)
>
0
:
with
open
(
self
.
_bond_angle_filename
,
'w'
)
as
fh
:
for
b
in
self
.
get_bond_angles
():
item
=
tuple
([
p
.
idx
for
p
in
b
[:
-
1
]]
+
[
str
(
p
)
for
p
in
b
[
-
1
]])
fh
.
write
(
"BONDANGLE %d %d %d %s %s %s
\n
"
%
item
)
def
dimensions_from_structure
(
self
,
padding_factor
=
1.5
,
isotropic
=
False
):
def
dimensions_from_structure
(
self
,
padding_factor
=
1.5
,
isotropic
=
False
):
## TODO: cache coordinates using numpy arrays for quick min/max
## TODO: cache coordinates using numpy arrays for quick min/max
raise
(
NotImplementedError
)
raise
(
NotImplementedError
)
...
...
mrdna/arbdmodel/nonbonded.py
View file @
9f55d328
...
@@ -58,12 +58,13 @@ class TabulatedPotential(NonbondedScheme):
...
@@ -58,12 +58,13 @@ class TabulatedPotential(NonbondedScheme):
## Bonded potentials
## Bonded potentials
class
BasePotential
():
class
BasePotential
():
def
__init__
(
self
,
r0
,
rRange
=
(
0
,
50
),
resolution
=
0.1
,
maxForce
=
None
,
max_potential
=
None
,
prefix
=
"potentials/"
):
def
__init__
(
self
,
r0
,
rRange
=
(
0
,
50
),
resolution
=
0.1
,
maxForce
=
None
,
max_potential
=
None
,
zero
=
"min"
,
prefix
=
"potentials/"
):
self
.
r0
=
r0
self
.
r0
=
r0
self
.
rRange
=
rRange
self
.
rRange
=
rRange
self
.
resolution
=
resolution
self
.
resolution
=
resolution
self
.
maxForce
=
maxForce
self
.
maxForce
=
maxForce
self
.
prefix
=
prefix
self
.
prefix
=
prefix
self
.
zero
=
zero
self
.
periodic
=
False
self
.
periodic
=
False
self
.
type_
=
"None"
self
.
type_
=
"None"
self
.
max_potential
=
max_potential
self
.
max_potential
=
max_potential
...
@@ -111,15 +112,16 @@ class BasePotential():
...
@@ -111,15 +112,16 @@ class BasePotential():
u
[
0
]
=
0
u
[
0
]
=
0
u
[
1
:]
=
np
.
cumsum
(
f
*
np
.
diff
(
r
))
u
[
1
:]
=
np
.
cumsum
(
f
*
np
.
diff
(
r
))
u
=
u
-
np
.
min
(
u
)
if
self
.
zero
==
"min"
:
u
=
u
-
np
.
min
(
u
)
np
.
savetxt
(
self
.
filename
(),
np
.
array
([
r
,
u
]).
T
,
fmt
=
"%f"
)
np
.
savetxt
(
self
.
filename
(),
np
.
array
([
r
,
u
]).
T
,
fmt
=
"%f"
)
class
HarmonicPotential
(
BasePotential
):
class
HarmonicPotential
(
BasePotential
):
def
__init__
(
self
,
k
,
r0
,
rRange
,
resolution
,
maxForce
,
max_potential
,
prefix
,
correct_geometry
=
False
):
def
__init__
(
self
,
k
,
r0
,
rRange
,
resolution
,
maxForce
,
max_potential
,
zero
=
"min"
,
correct_geometry
=
False
,
prefix
=
'./'
):
self
.
k
=
k
self
.
k
=
k
self
.
kscale_
=
None
self
.
kscale_
=
None
BasePotential
.
__init__
(
self
,
r0
,
rRange
,
resolution
,
maxForce
,
max_potential
,
prefix
)
BasePotential
.
__init__
(
self
,
r0
,
rRange
,
resolution
,
maxForce
,
max_potential
,
zero
,
prefix
)
def
filename
(
self
):
def
filename
(
self
):
return
"%s%s-%.3f-%.3f.dat"
%
(
self
.
prefix
,
self
.
type_
,
return
"%s%s-%.3f-%.3f.dat"
%
(
self
.
prefix
,
self
.
type_
,
...
@@ -143,8 +145,8 @@ class HarmonicPotential(BasePotential):
...
@@ -143,8 +145,8 @@ class HarmonicPotential(BasePotential):
# self.kscale_ = 1.0
# self.kscale_ = 1.0
class
HarmonicBond
(
HarmonicPotential
):
class
HarmonicBond
(
HarmonicPotential
):
def
__init__
(
self
,
k
,
r0
,
rRange
=
(
0
,
50
),
resolution
=
0.1
,
maxForce
=
None
,
max_potential
=
None
,
prefix
=
"potentials/"
,
correct_geometry
=
False
,
temperature
=
295
):
def
__init__
(
self
,
k
,
r0
,
rRange
=
(
0
,
50
),
resolution
=
0.1
,
maxForce
=
None
,
max_potential
=
None
,
prefix
=
"potentials/"
,
zero
=
"min"
,
correct_geometry
=
False
,
temperature
=
295
):
HarmonicPotential
.
__init__
(
self
,
k
,
r0
,
rRange
,
resolution
,
maxForce
,
max_potential
,
prefix
)
HarmonicPotential
.
__init__
(
self
,
k
,
r0
,
rRange
,
resolution
,
maxForce
,
max_potential
,
zero
=
zero
,
correct_geometry
=
correct_geometry
,
prefix
=
prefix
)
self
.
type_
=
"gbond"
if
correct_geometry
else
"bond"
self
.
type_
=
"gbond"
if
correct_geometry
else
"bond"
self
.
kscale_
=
1.0
self
.
kscale_
=
1.0
self
.
correct_geometry
=
correct_geometry
self
.
correct_geometry
=
correct_geometry
...
@@ -161,22 +163,22 @@ class HarmonicBond(HarmonicPotential):
...
@@ -161,22 +163,22 @@ class HarmonicBond(HarmonicPotential):
class
HarmonicAngle
(
HarmonicPotential
):
class
HarmonicAngle
(
HarmonicPotential
):
def
__init__
(
self
,
k
,
r0
,
rRange
=
(
0
,
181
),
resolution
=
0.1
,
maxForce
=
None
,
max_potential
=
None
,
prefix
=
"potentials/"
):
def
__init__
(
self
,
k
,
r0
,
rRange
=
(
0
,
181
),
resolution
=
0.1
,
maxForce
=
None
,
max_potential
=
None
,
zero
=
"min"
,
prefix
=
"potentials/"
):
HarmonicPotential
.
__init__
(
self
,
k
,
r0
,
rRange
,
resolution
,
maxForce
,
max_potential
,
prefix
)
HarmonicPotential
.
__init__
(
self
,
k
,
r0
,
rRange
,
resolution
,
maxForce
,
max_potential
,
zero
=
zero
,
prefix
=
prefix
)
self
.
type_
=
"angle"
self
.
type_
=
"angle"
self
.
kscale_
=
(
180.0
/
np
.
pi
)
**
2
self
.
kscale_
=
(
180.0
/
np
.
pi
)
**
2
class
HarmonicDihedral
(
HarmonicPotential
):
class
HarmonicDihedral
(
HarmonicPotential
):
def
__init__
(
self
,
k
,
r0
,
rRange
=
(
-
180
,
180
),
resolution
=
0.1
,
maxForce
=
None
,
max_potential
=
None
,
prefix
=
"potentials/"
):
def
__init__
(
self
,
k
,
r0
,
rRange
=
(
-
180
,
180
),
resolution
=
0.1
,
maxForce
=
None
,
max_potential
=
None
,
zero
=
"min"
,
prefix
=
"potentials/"
):
HarmonicPotential
.
__init__
(
self
,
k
,
r0
,
rRange
,
resolution
,
maxForce
,
max_potential
,
prefix
)
HarmonicPotential
.
__init__
(
self
,
k
,
r0
,
rRange
,
resolution
,
maxForce
,
max_potential
,
zero
=
zero
,
prefix
=
prefix
)
self
.
periodic
=
True
self
.
periodic
=
True
self
.
type_
=
"dihedral"
self
.
type_
=
"dihedral"
self
.
kscale_
=
(
180.0
/
np
.
pi
)
**
2
self
.
kscale_
=
(
180.0
/
np
.
pi
)
**
2
class
WLCSKBond
(
BasePotential
):
class
WLCSKBond
(
BasePotential
):
""" ## https://aip.scitation.org/doi/full/10.1063/1.4968020 """
""" ## https://aip.scitation.org/doi/full/10.1063/1.4968020 """
def
__init__
(
self
,
d
,
lp
,
kT
,
rRange
=
(
0
,
50
),
resolution
=
0.02
,
maxForce
=
100
,
max_potential
=
None
,
prefix
=
"potentials/"
):
def
__init__
(
self
,
d
,
lp
,
kT
,
rRange
=
(
0
,
50
),
resolution
=
0.02
,
maxForce
=
100
,
max_potential
=
None
,
zero
=
"min"
,
prefix
=
"potentials/"
):
BasePotential
.
__init__
(
self
,
0
,
rRange
,
resolution
,
maxForce
,
max_potential
,
prefix
)
BasePotential
.
__init__
(
self
,
0
,
rRange
,
resolution
,
maxForce
,
max_potential
,
zero
,
prefix
)
self
.
type_
=
"wlcbond"
self
.
type_
=
"wlcbond"
self
.
d
=
d
# separation
self
.
d
=
d
# separation
self
.
lp
=
lp
# persistence length
self
.
lp
=
lp
# persistence length
...
@@ -213,8 +215,8 @@ class WLCSKBond(BasePotential):
...
@@ -213,8 +215,8 @@ class WLCSKBond(BasePotential):
class
WLCSKAngle
(
BasePotential
):
class
WLCSKAngle
(
BasePotential
):
## https://aip.scitation.org/doi/full/10.1063/1.4968020
## https://aip.scitation.org/doi/full/10.1063/1.4968020
def
__init__
(
self
,
d
,
lp
,
kT
,
rRange
=
(
0
,
181
),
resolution
=
0.5
,
maxForce
=
None
,
max_potential
=
None
,
prefix
=
"potentials/"
):
def
__init__
(
self
,
d
,
lp
,
kT
,
rRange
=
(
0
,
181
),
resolution
=
0.5
,
maxForce
=
None
,
max_potential
=
None
,
zero
=
"min"
,
prefix
=
"potentials/"
):
BasePotential
.
__init__
(
self
,
180
,
rRange
,
resolution
,
maxForce
,
max_potential
,
prefix
)
BasePotential
.
__init__
(
self
,
180
,
rRange
,
resolution
,
maxForce
,
max_potential
,
zero
,
prefix
)
self
.
type_
=
"wlcangle"
self
.
type_
=
"wlcangle"
self
.
d
=
d
# separation
self
.
d
=
d
# separation
self
.
lp
=
lp
# persistence length
self
.
lp
=
lp
# persistence length
...
...
Write
Preview
Supports
Markdown
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