hplattice.Chain¶
-
class
hplattice.Chain.
Chain
(hpstring, initial_vec)[source]¶ The 2D HP lattice chain. The chain is defined by monomers (beads), which can be either Hydrophobic (H) or Polar (P). By convention, the first monomer in the chain is fixed at the origin on a two-dimensional square lattice.
Adjacent monomers are connected by bonds. The directionality of the bonds is stored in
Vectors
, and each bond-vector is stored as an integer: 0 (up), 1 (left), 2 (down) or 3 (right). A chain with \(N\) monomers has \(N-1\) vectors.In addition to the vector representation of the chain,
Chain
objects also store the 2D coordinates of each monomer. The set of coordinates is stored in aCoords
object.Parameters: - hpstring (str) – String that specifies H or P for each monomer.
Example:
PHPPHP
- initial_vec (list) – List that specifies the direction of each bond.
Example:
[0,0,1,2,1]
, which would correspond to up, up, left, down, left.
-
class
Coords
(num_monomers=0)[source]¶ Coords
is the set of monomer coordinates for a chain.Parameters: num_monomers (int) – The number of monomers in the chain. -
as_npy_array
()[source]¶ Convert
Coords
object tonumpy.ndarray
Returns: array of coordinates Return type: numpy.ndarray
-
distance_between_pts
(idx1, idx2)[source]¶ Compute the cartesian distance between two monomers.
Parameters: - idx1 (int) – the index of a monomer
- idx2 (int) – the index of a monomer
-
get
(idx=None)[source]¶ Get the coordinates of a monomer.
Parameters: idx (int) – the index of a monomer
-
grow
()[source]¶ Append another monomer to C-terminus of the chain, one space above the current C-terminal monomer.
-
is_viable
()[source]¶ Check for steric overlap and chain crossovers, neither of which are allowed.
Returns: True
if no problems are found with the chain.Return type: bool
-
rotate_down_to_left
(idx)[source]¶ Decrements the x-coord and increments the y-coord of a monomer.
Parameters: idx (int) – the index of a monomer
-
rotate_right_to_down
(idx)[source]¶ Decrements the x-coord and decrements the y-coord of a monomer.
Parameters: idx (int) – the index of a monomer
-
rotate_up_to_right
(idx)[source]¶ Increments the x-coord and decrements the y-coord of a monomer.
Parameters: idx (int) – the index of a monomer
-
-
class
Vectors
(vec_list=None)[source]¶ Vectors
stores the directionality of the bonds between monomers in aChain
. Each bond-vector is stored as an integer: 0 (up), 1 (left), 2 (down) or 3 (right). A chain with \(N\) monomers has \(N-1\) vectors.Parameters: vec_list (list) – List that specifies the direction of each bond. Example: [0,0,1,2,1]
, which would correspond to up, up, left, down, left.-
as_npy_array
()[source]¶ Convert
Vectors
object tonumpy.ndarray
Returns: array of vector values Return type: numpy.ndarray
-
-
contactstate
()[source]¶ Find all contacts between pairs of
H
monomers that are separated by at least three positions along the chain, i.e. will not include(i, i+1)
and(i, i+2)
pairs.Returns: list of (idx1,idx2)
contacts (tuples)Return type: list
-
do_crankshaft
(vecindex)[source]¶ Swap the values of a pair of chain vectors that are next-nearest neighbors.
Parameters: vecindex (int) – swap vecindex
withvecindex+2
-
do_rigid_rot
(vecindex, direction)[source]¶ Rotate a chain vector clockwise or counterclockwise. The possible clockwise rotations are:
0 –> 1
1 –> 2
2 –> 3
3 –> 0
Parameters: - vecindex (int) – a valid vector index
- direction (int) –
1
for clockwise,-1
for counterclockwise
-
do_three_bead_flip
(vecindex)[source]¶ Swap the values of a pair of neighboring chain vectors.
Parameters: vecindex (int) – swap vecindex
withvecindex+1
-
energy
(epsilon=0.0)[source]¶ Compute energy of chain, based on hydrophobic contacts.
Parameters: epsilon (float) – the energy of one hydrophobic contact. Returns: the total energy of the chain. Return type: float
-
get_vec_length
()[source]¶ Returns: The number of vectors in the chain, which should be one less than the number of monomers. Return type: int
-
is_viable
()[source]¶ Check for steric overlap and chain crossovers, neither of which are allowed.
Returns: True
if no problems are found with the chain.Return type: bool
-
nextviable
()[source]¶ Check for steric overlap and chain crossovers in the not-yet-accepted next configuration of the chain. This is usually called before accepting a monte carlo move to make sure that the chain doesn’t end up in a disallowed state.
Returns: True
if no problems are found with the chain.Return type: bool
-
nonsym
()[source]¶ Many of the conformations are related by rotations and reflections. We define a “non-symmetric” conformation to have the first direction
0
and the first turn be a1
(right turn)Returns: 1
if the chain is non-symmetric,0
otherwise.Return type: int
-
shift
()[source]¶ Shifts the chain vector to the ‘next’ list, according to an enumeration scheme where the most distal chain vector is incremented 0->1->2->3. After 3, the most distal vector element is removed, and the next most distal element is incremented. If there are multiple “3” vectors, this process is done recursively.
Example:
[0,0,0,0] –> [0,0,0,1]
[0,0,1,2] –> [0,0,1,3]
[0,1,0,3] –> [0,1,1]
[0,3,3,3] –> [1]
This operation is very useful for enumerating the full space of chain conformations.
Returns: 1
if no more shifts are possible and0
otherwise.Return type: int
- hpstring (str) – String that specifies H or P for each monomer.
Example: