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
71aa2903
Commit
71aa2903
authored
Mar 21, 2018
by
cmaffeo2
Browse files
Updated methods for iterating through connections between segments
parent
a36bc78c
Changes
1
Hide whitespace changes
Inline
Sidebyside
segmentmodel.py
View file @
71aa2903
...
...
@@ 14,9 +14,13 @@ import types
"""
TODO:
 document

 handle crossovers
 connections in the middle of a segment?
 merge beads at ends of connected helices?
 map to atomic representation
 remove performance bottlenecks
 test for large systems
 assign sequence
"""
class
Location
():
...
...
@@ 42,12 +46,25 @@ class ConnectableElement():
def
__init__
(
self
,
connections
=
[]):
self
.
connections
=
connections
def
get_connections_and_locations
(
self
,
type_
=
None
):
""" Returns a list with each entry of the form:
connection, location_in_self, location_in_other """
ret
=
[]
for
c
in
self
.
connections
:
if
type_
is
None
or
c
.
type_
==
type_
:
if
c
.
A
.
container
==
self
:
ret
.
append
(
[
c
,
c
.
A
,
c
.
B
]
)
elif
c
.
B
.
container
==
self
:
ret
.
append
(
[
c
,
c
.
B
,
c
.
A
]
)
else
:
raise
Exception
(
"Object contains connection that fails to refer to object"
)
return
ret
def
_connect
(
self
,
other
,
connection
):
self
.
connections
.
append
(
connection
)
other
.
connections
.
append
(
connection
)
def
_find_connections
(
self
,
loc
):
return
[
c
for
c
in
self
.
connections
if
c
.
A
==
loc
or
c
.
B
==
loc
]
# def _find_connections(self, loc):
# return [c for c in self.connections if c.A == loc or c.B == loc]
class
Segment
(
ConnectableElement
,
Group
):
...
...
@@ 65,6 +82,7 @@ class Segment(ConnectableElement, Group):
mass
=
300
,
radius
=
1
,
)
# orientation_bond = HarmonicBond(10,2)
orientation_bond
=
HarmonicBond
(
30
,
1.5
,
rRange
=
(
0
,
500
)
)
...
...
@@ 444,19 +462,27 @@ class SegmentModel(ArbdModel):
self
.
useNonbondedScheme
(
nbDnaScheme
)
def
get_connections
(
self
,
type_
=
None
):
""" Find all connections in model, without doublecounting """
added
=
set
()
ret
=
[]
for
s
in
self
.
segments
:
items
=
[
e
for
e
in
s
.
get_connections_and_locations
(
type_
)
if
e
[
0
]
not
in
added
]
added
.
update
([
e
[
0
]
for
e
in
items
])
ret
.
extend
(
items
)
return
ret
def
_get_intrahelical_beads
(
self
):
ret
=
[]
for
s
in
self
.
segments
:
ret
.
extend
(
s
.
get_all_consecutive_beads
(
2
)
)
for
s
in
self
.
segments
:
for
c
in
s
.
connections
:
if
c
.
type_
==
"intrahelical"
:
if
c
.
A
.
container
==
s
:
# avoid doublecounting
b1
,
b2
=
[
loc
.
particle
for
loc
in
(
c
.
A
,
c
.
B
)]
for
b
in
(
b1
,
b2
):
assert
(
b
is
not
None
)
ret
.
append
(
[
b1
,
b2
]
)
for
c
,
A
,
B
in
self
.
get_connections
(
"intrahelical"
):
# TODO: check that b1,b2 not same
b1
,
b2
=
[
l
.
particle
for
l
in
(
A
,
B
)]
for
b
in
(
b1
,
b2
):
assert
(
b
is
not
None
)
ret
.
append
(
[
b1
,
b2
]
)
return
ret
def
_get_intrahelical_angle_beads
(
self
):
...
...
@@ 464,47 +490,43 @@ class SegmentModel(ArbdModel):
for
s
in
self
.
segments
:
ret
.
extend
(
s
.
get_all_consecutive_beads
(
3
)
)
for
s1
in
self
.
segments
:
for
c
in
s1
.
connections
:
if
c
.
A
.
container
!=
s1
:
continue
s2
=
c
.
B
.
container
if
c
.
type_
==
"intrahelical"
:
b1
,
b2
=
[
loc
.
particle
for
loc
in
(
c
.
A
,
c
.
B
)]
for
b
in
(
b1
,
b2
):
assert
(
b
is
not
None
)
## TODO: make this code more robust
## TODO: find bug that makes things be out of order
try
:
b0
=
s1
.
get_beads_before_bead
(
b1
,
1
)
assert
(
len
(
b0
)
==
1
)
b0
=
b0
[
0
]
assert
(
b0
is
not
None
)
ret
.
append
(
[
b0
,
b1
,
b2
]
)
except
:
...
try
:
b0
=
s1
.
get_beads_after_bead
(
b1
,
1
)
assert
(
len
(
b0
)
==
1
)
b0
=
b0
[
0
]
assert
(
b0
is
not
None
)
ret
.
append
(
[
b2
,
b1
,
b0
]
)
except
:
...
try
:
b3
=
s2
.
get_beads_before_bead
(
b2
,
1
)
assert
(
len
(
b3
)
==
1
)
b3
=
b3
[
0
]
assert
(
b3
is
not
None
)
ret
.
append
(
[
b3
,
b2
,
b1
]
)
except
:
...
try
:
b3
=
s2
.
get_beads_after_bead
(
b2
,
1
)
assert
(
len
(
b3
)
==
1
)
b3
=
b3
[
0
]
assert
(
b3
is
not
None
)
ret
.
append
(
[
b1
,
b2
,
b3
]
)
except
:
...
for
c
,
A
,
B
in
self
.
get_connections
(
"intrahelical"
):
s1
,
s2
=
[
loc
.
container
for
loc
in
(
A
,
B
)]
b1
,
b2
=
[
loc
.
particle
for
loc
in
(
A
,
B
)]
for
b
in
(
b1
,
b2
):
assert
(
b
is
not
None
)
## TODO: make this code more robust
try
:
b0
=
s1
.
get_beads_before_bead
(
b1
,
1
)
assert
(
len
(
b0
)
==
1
)
b0
=
b0
[
0
]
assert
(
b0
is
not
None
)
ret
.
append
(
[
b0
,
b1
,
b2
]
)
except
:
...
try
:
b0
=
s1
.
get_beads_after_bead
(
b1
,
1
)
assert
(
len
(
b0
)
==
1
)
b0
=
b0
[
0
]
assert
(
b0
is
not
None
)
ret
.
append
(
[
b2
,
b1
,
b0
]
)
except
:
...
try
:
b3
=
s2
.
get_beads_before_bead
(
b2
,
1
)
assert
(
len
(
b3
)
==
1
)
b3
=
b3
[
0
]
assert
(
b3
is
not
None
)
ret
.
append
(
[
b3
,
b2
,
b1
]
)
except
:
...
try
:
b3
=
s2
.
get_beads_after_bead
(
b2
,
1
)
assert
(
len
(
b3
)
==
1
)
b3
=
b3
[
0
]
assert
(
b3
is
not
None
)
ret
.
append
(
[
b1
,
b2
,
b3
]
)
except
:
...
return
ret
# def _get_intrahelical_bead_pairs_within(self, cutoff):
...
...
@@ 649,10 +671,8 @@ class SegmentModel(ArbdModel):
s
.
_generate_beads
(
self
,
max_basepairs_per_bead
,
max_nucleotides_per_bead
)
""" Combine beads at junctions as needed """
for
s
in
segments
:
for
c
in
s
.
connections
:
if
c
.
A
.
container
==
s
:
...
for
c
,
A
,
B
in
self
.
get_connections
():
...
""" Reassign bead types """
if
self
.
DEBUG
:
print
(
"Assigning bead types"
)
...
...
@@ 813,13 +833,10 @@ class SegmentModel(ArbdModel):
parent
.
add_dihedral
(
o1
,
b1
,
b2
,
o2
,
pot
)
""" Add connection potentials """
for
s
in
segments
:
for
c
in
s
.
connections
:
if
c
.
type_
==
"terminal_crossover"
:
if
c
.
A
.
container
==
s
:
b1
,
b2
=
[
loc
.
particle
for
loc
in
(
c
.
A
,
c
.
B
)]
pot
=
self
.
get_bond_potential
(
4
,
18.5
)
self
.
add_bond
(
b1
,
b2
,
pot
)
for
c
,
A
,
B
in
self
.
get_connections
(
"terminal_crossover"
):
b1
,
b2
=
[
loc
.
particle
for
loc
in
(
c
.
A
,
c
.
B
)]
pot
=
self
.
get_bond_potential
(
4
,
18.5
)
self
.
add_bond
(
b1
,
b2
,
pot
)
self
.
_updateParticleOrder
()
...
...
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