Polymer
- class Polymer(firstMonomer: Monomer, keep_resids=False)[source]
Bases:
objectCreate a Polymer from a Monomer and ‘extend’ it with more Monomers to create a Polymer with the desired structure and connectivity.
- copy() Polymer[source]
Use MDAnalysis Universe.copy() to create a new MDAnalysis Universe that is an exact copy of this one containing the polymer. Deepcopy is not used as it can be problematic with open file sockets.
- Returns:
A new Polymer that is an exact copy of this polymer
- Return type:
- dihedral_solver(pairlist, dummies='X*', cutoff=0.7, backwards_only=True)[source]
Converts the shuffled conformation (i.e. after
shuffle()) into one without overlapping atoms by resolving dihedrals- Parameters:
pairlist (list of dicts of atom pairs) – list of dicts of atom pairs, created with
gen_pairlist(), e.g. [{J,J_resid,K,K_resid,mult}]dummies (str, optional) – the names of dummy atoms, to be discluded from the distance calculation. Passed to
dist(), defaults to ‘X*’cutoff (float, optional) – maximum interatomic distance for atoms to be considered overlapping, defaults to 0.7
backwards_only (bool, optional) – passed to
dist()to decide if clash checking is done from residue 1 up to max([J_resid,K_resid]) for the current dihedral (if True), or along the entire polymer (if False) defaults to True
- Returns:
True if unable to resolve dihedrals or False if dihedrals all resolved and no clashes detected
- Return type:
- dist(J, J_resid, K, K_resid, dummies='X*', backwards_only=True)[source]
Given a pair of bonded atoms J and K, get minimum distance between atoms on one side of a bond, and atoms on the other side of the bond. This is useful for detecting overlapping atoms.
- Parameters:
J (str) – the name of the first atom in the bond
J_resid (int) – the resid of the first atom in the bond
K (str) – the name of the second atom in the bond
K_resid (int) – the resid of the second atom in the bond
dummies (str, optional) – the names of dummy atoms, to be excluded from the distance calculation, defaults to ‘X*’
backwards_only (bool, optional) – only consider atoms from residues 1 to max([J_resid,K_resid]), and do not consider atoms further along the chain. This is useful for solving dihedrals algorithmically, as only clashes in the solved region of the polymer are considered, defaults to True
- Returns:
MDAnalysis.analysis.distance_array of the minimum distances between atoms on both halves of the bond
- Return type:
mda.analysis.distance_array
- extend(monomer, n, nn, names, joins, ortho=[1, 1, 1], linearise=False, beta=0)[source]
Extend the polymer by adding a monomer
- Parameters:
monomer (Monomer) – the monomer to add to the polymer
n (int) – residue (identified by its resid) to extend from
nn (int) – residue (identified by its resid) to extend to (i.e. the new residue)
names (dict) –
a dictionary of single ‘key:value’ pairs with keys P, Q, R and S for the atoms that are used to define the mapping during polymer extension.
There are two additional optional values, V1 and V2, which are only required in linear extend.
The definition is as follows:
Atoms P and R are a pair of bonded atoms located in the incoming monomer.
Atoms Q and S are a pair of bonded atoms located in residue n of the existing polymer.
Atoms P and Q are equivalent in the final polymer, and either P or Q is a dummy atom.
Atoms R and S are equivalent in the final polymer, and either R or S is a dummy atom.
Bonds PR and QS are equivalent in the final polymer.
extend() is agnostic as to which atom in each pair is real, and which atom is a dummy after extension, you can use renamer() to explicilty set dummy atoms * Atoms V1 and V2 a pair of atoms located in the incoming monomer.
joins (list of 2 item tuples) – defines a pair of atoms to connected after extension the first atom in a pair belongs to residue ‘n’, and the second belongs to residue ‘nn’
ortho (list, optional) – used for linearise and defines which axis to align along (e.g. align along x with ortho=[1,0,0]), defaults to [1,1,1]
linearise (bool, optional) – make the polymer linear. Good for debugging and visually confirming structure is correct, defaults to False
beta (int, optional) – beta is used to group monomers into categories, so that each branch can be separated. Beta is analogous to segments. The tempfactors attribute of all of the atoms in the incoming monomer are set to the value of beta, defaults to 0
- For example:
{‘P’:’CMA’,’Q’:’CA’,’R’:’CN’,’S’:’C’}, with n=1 and nn=2 and joins=[(‘C’,’CA’)] would produce a polymer of ‘…-CA1-C1-CA2-C2-…’
- Further notes:
n and nn enable branching by specifying from and to connections between monomers and beta is analogous to segments
- extend a polymer ‘u’ by a monomer ‘u_’, by fitting the backbone atoms (P2, Q2) from the new monomer to (P1,Q1) from the existing residue n,
then joins the monomer nn to the existing universe with a bond between each pair of atoms in joins
- ATOM NOMENCLATURE:
P1 and Q1 are atoms in monomer n
P2 and Q2 are dummy atoms in monomer nn, which correspond to the atoms P1 and Q1
- R and S are atoms in monomer nn that describe a vector to be aligned to the ortho vector during the linearise fit;
intended for making straight orthoganal branches for ease of visibility this must be chosen carefully so the rotation doe not break stereochemistry or alignment
- JOINS NOMENCLATURE:
joins contains pairs of atoms to be linked, of the form (X_n,Y_nn)
X_n is some atom in residue n, the final residue before extension
Y_n+1 is some atom in residue nn, the new residue
- Note:
this function preserves all dummy atoms. Removing dummy atoms during extension causes substantial problems with indexing. They must only be removed once the polymer is fully built. Save your polymer to a .gro or .pdb file with the PDB.save() method, which will strip any dummy atoms.
- gen_pairlist(J, K, first_resid=1, last_resid=999, resid_step=1, same_res=True, mult=3)[source]
Generates a list of dicts of atom pairs for use in
shuffler()ordihedral_solver().- Parameters:
J (str) – the name of the first atom in the bond
K (str) – the name of the second atom in the bond
first_resid (int, optional) – resid of first residue to include in pairlist, defaults to 1
last_resid (int, optional) – resid of last residue to include in pairlist, defaults to 999
resid_step (int, optional) – interval between each resid, useful for only generating a dict in the pairlist for every nth residue, defaults to 1
same_res (bool, optional) – if True, paired atoms are bonded within the same residue, if False assumes that paired atoms J and K form a bond between residue n and residue n+1, defaults to True
mult (int, optional) – the multiplicity of the dihedral centered over J-K, defaults to 3
- Returns:
a list of dicts of atom pairs
- Return type:
list of dicts
- gencomp(length, fill, middle, count=True, frac=False)[source]
Deprecated and unsupported, use with caution. Generate the linear conformation of a polymer from a given length, specified monomer composition and a dictionary of monomers. Only used by ‘polyconf_automatic’ and should not be used otherwise.
- Parameters:
mdict (dict) – dictionary of resnames making up the ‘middle’ of the polymer (i.e. not terminal residues) with how many of each type
length (int) – desired length of the polymer (i.e. number of monomers)
fill (list) – list of monomers which can be used to build the polymer middle (i.e. are not terminal monomers) if there are not enough in ‘middle’ to complete the monomer
middle (list) – list of monomers to build the polymer from
count (bool, optional) – generate absolute composition with counts (e.g. 4 of monomer A and 12 of monomer B), defaults to True
frac (bool, optional) – generate relative composition with fractions (e.g. 25% monomer A and 75% monomer B), defaults to False
- Returns:
a list with the sequence of randomly ordered monomers of the desired length and composition to build the polymer
- Return type:
- maxresid()[source]
Returns maximum resid in the polymer
- Returns:
the polymer’s current highest resid
- Return type:
- newresid()[source]
Returns maximum resid in the polymer plus 1, thus the next available resid number an incoming monomer can be assigned.
- Returns:
the polymer’s current highest resid plus one.
- Return type:
- renamer(resid, namein, nameout='X')[source]
Change selected atom names to a new name. Intended to flag dummy atoms for removal. Selected atoms are given a basename defined by the nameout argument, e.g. ‘X’ , and a number.
- rotate(J, J_resid, K, K_resid, mult=3, step=1)[source]
Given a pair of bonded atoms J and K within some torsion, uses _split_pol() to identify all atoms connected to J, then rotates them around vector JK by (step * int(360/mult)) degrees, rotating the dihedral centered over J-K by one step.
- Parameters:
J (str) – the name of the first atom in the torsion
J_resid (int) – the resid of the first atom in the torsion
K (str) – the name of the second atom in the torsion
K_resid (int) – the resid of the second atom in the torsion
mult (int, optional) – the multiplicity of the dihedral centered over J-K, defaults to 3
step (int, optional) – how many steps to rotate around the torsion, where one step = 320/mult degrees, defaults to 3
- select_atoms(selection) AtomGroup[source]
Selection method that selects atoms from the polymer’s MDAnalysis Universe by leveraging the MDAnalysis atom selection.
- Parameters:
selection (str) – MDAnalysis atom selection string, for more information on supported atom selection formats see MDAnalysis Atom selection language <https://userguide.mdanalysis.org/stable/selections.html>
- Returns:
An MDAnalysis AtomGroup containing only the selected atoms
- Return type:
mda.AtomGroup
- shuffle(J, J_resid, K, K_resid, dummies='X*', mult=3, cutoff=0.5, clashcheck=False, backwards_only=False)[source]
Given a pair of bonded atoms J and K, randomly rotates the dihedral between them a random amount with clashcheck=True, will check if the resulting structure has overlapping atoms, and will undo the rotation if so.
- Parameters:
J (str) – the name of the first atom in the torsion
J_resid (int) – the resid of the first atom in the torsion
K (str) – the name of the second atom in the torsion
K_resid (int) – the resid of the second atom in the torsion
dummies (str, optional) – the names of dummy atoms, to be excluded from the distance calculation. Passed to
dist(), defaults to ‘X*’mult (int, optional) – the multiplicity of the dihedral centered over J-K, defaults to 3
cutoff (float, optional) – maximum interatomic distance for atoms to be considered overlapping, defaults to 0.5
clashcheck (bool, optional) – check if the shuffle has introduced a clash, and if so reverses the shuffle, defaults to False
backwards_only (bool, optional) – passed to
dist()to decide if clash checking is done from residue 1 up to max([J_resid,K_resid]) (if True), or along the entire polymer (if False) defaults to False
- Returns:
True if clash detected, or False if no clash detected
- Return type:
- shuffler(pairlist, dummies='X*', cutoff=0.5, clashcheck=False)[source]
Shuffles each pair of bonded atoms in the provided pairlist with
shuffle()- Parameters:
pairlist (list of dicts of atom pairs) – list of dicts of atom pairs, created with
gen_pairlist(), e.g. [{J,J_resid,K,K_resid,mult}]dummies (str, optional) – _the names of dummy atoms, to be discluded from the distance calculation. Passed to
shuffle(), defaults to ‘X*’cutoff (float, optional) – maximum interatomic distance for atoms to be considered overlapping, defaults to 0.5
clashcheck (bool, optional) – check if the shuffle has introduced a clash, and if so reverses the shuffle, defaults to False