Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mrdna
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Operate
Environments
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
tbgl
tools
mrdna
Commits
ea7ba628
Commit
ea7ba628
authored
6 years ago
by
cmaffeo2
Browse files
Options
Downloads
Patches
Plain Diff
Improved fit for non-bonded potential to all-atom data
parent
4027b3ae
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
mrdna/model/nbPot.py
+89
-15
89 additions, 15 deletions
mrdna/model/nbPot.py
setup.py
+1
-0
1 addition, 0 deletions
setup.py
with
90 additions
and
15 deletions
mrdna/model/nbPot.py
+
89
−
15
View file @
ea7ba628
...
@@ -8,10 +8,11 @@ from mrdna import get_resource_path
...
@@ -8,10 +8,11 @@ from mrdna import get_resource_path
dxParam
=
-
1
dxParam
=
-
1
def
maxForce
(
x
,
u
,
maxForce
=
40
):
def
maxForce
(
x
,
u
0
,
maxForce
=
40
):
maxForce
=
maxForce
*
0.014393265
# convert pN to kcal_mol/AA
maxForce
=
maxForce
*
0.014393265
# convert pN to kcal_mol/AA
dx
=
np
.
diff
(
x
)
dx
=
np
.
diff
(
x
)
f
=
-
np
.
diff
(
u
)
/
dx
f
=
-
np
.
diff
(
u0
)
/
dx
f
[
np
.
isnan
(
f
)
]
=
0
ids
=
np
.
where
(
f
>
maxForce
)[
0
]
ids
=
np
.
where
(
f
>
maxForce
)[
0
]
f
[
ids
]
=
maxForce
f
[
ids
]
=
maxForce
...
@@ -23,6 +24,7 @@ def maxForce(x,u,maxForce=40):
...
@@ -23,6 +24,7 @@ def maxForce(x,u,maxForce=40):
ids
=
np
.
where
(
x
>
40
)[
0
]
ids
=
np
.
where
(
x
>
40
)[
0
]
u
=
u
-
np
.
mean
(
u
[
ids
])
u
=
u
-
np
.
mean
(
u
[
ids
])
assert
(
np
.
isnan
(
u
).
sum
()
==
0
)
return
u
return
u
# d = np.loadtxt("resources/jj-nar-dna-pmf-20Mg-200Na.dat")
# d = np.loadtxt("resources/jj-nar-dna-pmf-20Mg-200Na.dat")
...
@@ -41,21 +43,48 @@ def parametric_potential(x,*parms):
...
@@ -41,21 +43,48 @@ def parametric_potential(x,*parms):
u
[
x
>
np
.
max
(
x0
)]
=
0
u
[
x
>
np
.
max
(
x0
)]
=
0
return
u
return
u
def
integrate
d
_potential
(
potfn
,
x
,
numBp
,
*
parms
):
def
integrate_potential
(
potfn
,
x
,
y
,
*
parms
):
u
=
np
.
zeros
(
np
.
shape
(
x
))
u
=
np
.
zeros
(
np
.
shape
(
x
))
for
h
in
range
(
-
numBp
,
numBp
+
1
)
:
for
h
in
y
:
r
=
np
.
sqrt
(
x
**
2
+
(
3.4
*
h
)
**
2
)
r
=
np
.
sqrt
(
x
**
2
+
h
**
2
)
r
[
r
<
1
]
=
1
r
[
r
<
1
]
=
1
u
=
u
+
potfn
(
r
,
*
parms
)
# * x/r
u
=
u
+
potfn
(
r
,
*
parms
)
# * x/r
return
u
return
u
# def integrated_potential(potfn,x,numBp,*parms):
# u = np.zeros(np.shape(x))
# for h in range(-numBp,numBp+1):
# r = np.sqrt(x**2 + (3.4*h)**2)
# r[r<1] = 1
# u = u + potfn(r,*parms) # * x/r
# return u
def
fitFun
(
x
,
*
parms
):
def
fitFun
(
x
,
*
parms
):
## 1-turn iteracting with 4 turns (more is not needed)
## 1-turn iteracting with 4 turns (more is not needed)
return
10
*
integrated_potential
(
parametric_potential
,
x
,
20
,
*
parms
)
y
=
np
.
arange
(
-
20
,
21
)
*
3.4
return
10
*
integrate_potential
(
parametric_potential
,
x
,
y
,
*
parms
)
def
fitFun5
(
x
,
*
parms
):
## 1-turn iteracting with 4 turns (more is not needed)
y
=
np
.
arange
(
-
20
,
21
)
*
(
5
*
3.4
)
return
5
*
5
*
integrate_potential
(
parametric_potential
,
x
,
y
,
*
parms
)
xinterp
=
np
.
linspace
(
np
.
min
(
x0
),
np
.
max
(
x0
),
1000
)
# interpolate potentialb
xinterp
=
np
.
linspace
(
np
.
min
(
x0
),
np
.
max
(
x0
),
1000
)
# interpolate potentialb
yinterp
=
interp1d
(
x0
,
y0
)(
xinterp
)
yinterp
=
interp1d
(
x0
,
y0
)(
xinterp
)
popt
,
pcov
=
opt
.
curve_fit
(
fitFun
,
xinterp
,
yinterp
,
p0
=
y0
/
10
**
2
)
# find fit to interpolated potential
def
fit_potential
(
bp1
,
bp2
):
assert
(
bp2
>=
bp1
)
def
fitFun
(
x
,
*
parms
):
## 1-turn iteracting with at least 4 turns (more is not needed)
y
=
np
.
arange
(
-
20
,
21
)
*
(
bp2
*
3.4
)
return
(
10.0
/
bp1
)
*
integrate_potential
(
parametric_potential
,
x
,
y
,
*
parms
)
popt
,
pcov
=
opt
.
curve_fit
(
fitFun
,
xinterp
,
yinterp
,
p0
=
y0
/
10
**
2
)
# find fit to interpolated potential
return
lambda
x
:
parametric_potential
(
x
,
*
popt
)
def
nbPot
(
x
,
bps1
,
bps2
):
def
nbPot
(
x
,
bps1
,
bps2
):
larger
=
np
.
max
([
bps1
,
bps2
])
larger
=
np
.
max
([
bps1
,
bps2
])
...
@@ -63,12 +92,31 @@ def nbPot(x,bps1,bps2):
...
@@ -63,12 +92,31 @@ def nbPot(x,bps1,bps2):
if
larger
>=
2
:
if
larger
>=
2
:
largerInt
=
int
(
0.5
*
larger
)
largerInt
=
int
(
0.5
*
larger
)
smaller
*=
larger
/
(
2
*
largerInt
)
smaller
*=
larger
/
(
2
*
largerInt
)
y
=
smaller
*
integrated_potential
(
parametric_potential
,
x
,
largerInt
,
*
popt
)
y
=
np
.
arange
(
-
largerInt
,
largerInt
+
1
)
*
3.4
u
=
smaller
*
integrate_potential
(
parametric_potential
,
x
,
y
,
*
popt
)
else
:
else
:
y
=
smaller
*
larger
*
parametric_potential
(
x
,
*
popt
)
u
=
smaller
*
larger
*
parametric_potential
(
x
,
*
popt
)
y
=
maxForce
(
x
,
y
,
100
)
u1
=
maxForce
(
x
,
u
,
100
)
y
=
savgol
(
y
,
int
(
5.0
/
(
x0
[
1
]
-
x0
[
0
])),
3
)
# u2 = savgol(u1, int(5.0/(x0[1]-x0[0])), 3)
return
y
u2
=
u
assert
(
np
.
sum
(
np
.
isnan
(
u2
))
==
0
)
return
u2
_pot_dict
=
{}
def
nbPot
(
x
,
bps1
,
bps2
):
larger
=
np
.
max
([
bps1
,
bps2
])
smaller
=
np
.
min
([
bps1
,
bps2
])
key
=
(
smaller
,
larger
)
if
key
not
in
_pot_dict
:
_pot_dict
[
key
]
=
fit_potential
(
*
key
)
u
=
_pot_dict
[
key
](
x
)
u1
=
maxForce
(
x
,
u
,
100
)
# u2 = savgol(u1, int(5.0/(x0[1]-x0[0])), 3)
u2
=
u
assert
(
np
.
sum
(
np
.
isnan
(
u2
))
==
0
)
return
u2
x
=
np
.
linspace
(
0
,
100
,
1001
)
x
=
np
.
linspace
(
0
,
100
,
1001
)
...
@@ -104,6 +152,32 @@ nbDnaScheme = nbDnaScheme()
...
@@ -104,6 +152,32 @@ nbDnaScheme = nbDnaScheme()
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
## run some tests
## run some tests
np
.
savetxt
(
"
jj-filtered.dat
"
,
np
.
array
((
x0
,
y0
)).
T
)
np
.
savetxt
(
"
jj-filtered.dat
"
,
np
.
array
((
x0
,
y0
)).
T
)
y
=
fitFun
(
x
,
*
popt
)
np
.
savetxt
(
"
1-bp-fit.dat
"
,
np
.
array
((
x
,
y
)).
T
),
# y = single_bp_pot = fitFun(x,*popt)
# np.savetxt("1-bp-fit.dat", np.array((x,y)).T),
# y = fitFun5(x,*popt5)
# np.savetxt("5-bp-fit.dat", np.array((x,y)).T),
# tmp = nbPot(np.linspace(20,45,100), 1,1)
# import pdb
# pdb.set_trace()
y
=
10
*
integrate_potential
(
nbPot
,
x
,
np
.
arange
(
-
20
,
20
)
*
3.4
,
1
,
1
)
np
.
savetxt
(
"
nb-1-1.dat
"
,
np
.
array
((
x
,
y
)).
T
),
y
=
10
*
integrate_potential
(
nbPot
,
x
,
np
.
arange
(
-
20
,
20
)
*
(
3.4
*
2
)
,
1
,
2
)
np
.
savetxt
(
"
nb-1-2.dat
"
,
np
.
array
((
x
,
y
)).
T
),
y
=
10
*
integrate_potential
(
nbPot
,
x
,
np
.
arange
(
-
20
,
20
)
*
(
3.4
*
5
)
,
1
,
5
)
np
.
savetxt
(
"
nb-1-5.dat
"
,
np
.
array
((
x
,
y
)).
T
),
y
=
5
*
integrate_potential
(
nbPot
,
x
,
np
.
arange
(
-
20
,
20
)
*
(
3.4
*
2
)
,
2
,
2
)
np
.
savetxt
(
"
nb-2-2.dat
"
,
np
.
array
((
x
,
y
)).
T
),
y
=
2
*
integrate_potential
(
nbPot
,
x
,
np
.
arange
(
-
20
,
20
)
*
(
3.4
*
5
)
,
5
,
5
)
np
.
savetxt
(
"
nb-5-5.dat
"
,
np
.
array
((
x
,
y
)).
T
),
# y = 10*5*integrate_potential(parametric_potential, x, np.arange(-20,20)*(3.4*5) , *popt)
# np.savetxt("scale-5-5.dat", np.array((x,y)).T),
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
0
View file @
ea7ba628
...
@@ -25,6 +25,7 @@ setuptools.setup(
...
@@ -25,6 +25,7 @@ setuptools.setup(
'
scipy>=1.1
'
,
'
scipy>=1.1
'
,
'
mdanalysis>=0.18
'
,
'
mdanalysis>=0.18
'
,
'
cadnano>=2.5.2.1
'
,
'
cadnano>=2.5.2.1
'
,
'
appdirs>=1.4
'
),
),
classifiers
=
(
classifiers
=
(
"
Programming Language :: Python :: 3
"
,
"
Programming Language :: Python :: 3
"
,
...
...
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