Polymer
- class Polymer(monomer)[source]
Bases:
objectRepresents a polymer, which is a Topology with a set of Junctions, in a molecular system.
- Parameters:
monomer (Monomer) – the Monomer to create the Polymer from.
- DFS(atom, visited: set, exclude=None)[source]
Depth first search of the Polymer to find all Atoms connected to the Atom provided in ‘atom’, including the Atom itself.
- Parameters:
atom (Atom) – the Atom to start the search from.
visited (set) – a set of atoms that have already been visited, and are connected to the Atom ‘atom’.
exclude (Atom, optional) – an Atom to exclude from the search (i.e. the other side of the junction), defaults to None.
- extend(monomer, from_junction_name: str, to_junction_name: str, keep_charge=True, bond_length_func=None)[source]
Extend the Polymer by joining a new Monomer to a Junction of the Polymer, via formation of a new Bond between the incoming Monomer’s ‘to_junction’ and the Polymer’s ‘from_junction’ monomer atoms.
When using this function, ensure that the Monomer and Polymer Junctions being connected have a matching two-atom depth overlap (i.e. use extended topologies). This will ensure that the new Bond, Angles and Dihedrals are correct.
For best results: * Do NOT extend a Polymer of a given format (e.g. gromos), with a Monomer of a different format (e.g. AMBER). This is not recommended as it is not the supported functionality and has NOT been tested. PolyTop may crash, produce an incorrect Polymer Topology or behave in an undefined manner. * Provide topologies where all atoms that will be lost have a partial charge of 0. This will ensure the charge of each atom in the resulting Polymer is identical to it’s charge in the provided Monomer it came from. * Ensure that all Junctions within the Polymer, and by extension the incoming Monomer, have unique names (unless they are redundant). If more than one Junction is present with a given name, one of these Junctions will be selected at random for the Polymer extension. This will result in unexpected Polymer topologies and prevent reproducibility.
- Parameters:
monomer (Monomer) – the Monomer to add to the Polymer
from_junction_name (str) – unique name of a Junction in the Polymer to create a new Bond from (i.e. extend from).
to_junction_name (str) – unique name of a Junction in the Monomer to create a new Bond to (i.e. extend to).
keep_charge (bool, optional) – if True, maintains the net charge of the Polymer by redistributing the charges of any lost atoms among the Atoms in the two most recently added residues of the Polymer (i.e. typically the incoming Monomer and the monomeric residue it is joining to), defaults to True
bond_length_func (a lambda function, optional) – a lambda function that takes 2 Bonds (the Polymer’s Junction Bond and the Monomer’s Junction Bond) and returns a Bond length for the new Bond, defaults to None (such that the new Bond length is the average of the two existing Junction’s Bonds)
- Raises:
ValueError – if from_junction_name does not correspond to a Junction present in the Polymer with the same name.
ValueError – if to_junction_name does not correspond to a Junction present in the Monomer with the same name.
- extra_bond(from_junction_name: str, to_junction_name: str, bond_length_func=None)[source]
Form an extra bond within the existing Polymer WITHOUT adding a new Monomer. Useful for creating double bonds or complex Polymer architectures.
- Parameters:
from_junction_name (str) – unique name of a Junction in the Polymer to create a new Bond from.
to_junction_name (str) – unique name of a Junction in the Polymer to create a new Bond to.
bond_length_func (a lambda function, optional) – a lambda function to calculate the length of the new Bond from the Bonds in the two provided Junctions, defaults to None (such that the new Bond length is the average of the two existing Junction’s Bonds)
- Raises:
ValueError – if either from_junction_name or to_junction_name do not correspond to a Junction present in the Polymer with the same name.
- classmethod from_dict(data: Dict[str, List[Dict[str, int | float]] | int | Dict[str, int | float] | None]) Polymer[source]
Create a new Polymer from a dictionary, such as that created with Polymer.to_dict().
The structure of the dictionary is as below: {“topology”: self.topology.to_dict(), “junctions”: self.junctions.to_dict()}
- classmethod load_from_file(filename: str) Polymer[source]
Load a JSON text dump of a Polymer, generated with Polymer.save_to_file(), to a new Polymer.
- save_to_file(filename: str) None[source]
Save and export the Polymer to a JSON text dump.
- Parameters:
file_path (str) – path to and desired name of output file.