HTPolyNet package

Submodules

HTPolyNet.driver.cli()[source]

cli Command-line interface

HTPolyNet.driver.fetch_example(args)[source]

fetch_example handles the fetch-example subcommand

Parameters:

args (argparse.Namespace) – parsed arguments

HTPolyNet.driver.info(args)[source]

info handles the info subcommmand

Parameters:

args (argparse.Namespace) – parsed arguments

HTPolyNet.driver.pack_example(args)[source]
HTPolyNet.driver.parameterize(args)[source]

parameterize handles the parameterize subcommand

Parameters:

args (argparse.Namespace) – parsed arguments

HTPolyNet.driver.run(args)[source]

run handles the run subcommand

Parameters:

args (argparse.Namespace) – parsed arguments

HTPolyNet.ambertools.GAFFParameterize(inputPrefix, outputPrefix, input_structure_format='mol2', **kwargs)[source]

GAFFParameterize manages execution of antechamber, tleap, and parmchk2 to generate GAFF parameters

Parameters:
  • inputPrefix (str) – basename of input structure file

  • outputPrefix (str) – basename of output files

  • input_structure_format (str, optional) – format of input structure file, defaults to ‘mol2’; ‘pdb’ is other option

Raises:

parmed.exceptions.GromacsError – if parmed fails

class HTPolyNet.analyze.Analyze(indict, strict=True)[source]

Bases: object

allowed_keys = ['gromacs', 'command', 'subdir', 'options', 'links', 'outfile', 'console-input', 'matchlines']
default_params = {'gromacs': {'gmx': 'gmx'}}
do(**gromacs_dict)[source]

do handles executing the analysis

parse_console_output()[source]
required_keys = ['command', 'subdir']
class HTPolyNet.analyze.AnalyzeConfiguration[source]

Bases: object

handles reading and parsing an analysis input config file. Config file format

  • { key1: {<paramdict>}}

  • { key2: {<paramdict>}}

The config file is a list of single-element dictionaries, whose single keyword indicates the type of analysis to be run; analyses are run in the order they appear in the config file.

default_class

alias of Analyze

parse(**kwargs)[source]

parse parses a PostsimConfiguration file to build the list of stages to run

predefined_classes = {'density': <class 'HTPolyNet.analyze.AnalyzeDensity'>, 'freevolume': <class 'HTPolyNet.analyze.AnalyzeFFV'>}
classmethod read(filename, parse=True, **kwargs)[source]

read generates a new PostsimConfiguration object by reading in the JSON or YAML file indicated by filename

Parameters:
  • filename (str) – name of file from which to read new PostsimConfiguration object

  • parse (bool, optional) – if True, parse the input configuration file, defaults to True

Raises:

Exception – if extension of filename is not ‘.json’ or ‘.yaml’ or ‘.yml’

Returns:

a new PostsimConfiguration object

Return type:

PostsimConfiguration

class HTPolyNet.analyze.AnalyzeDensity(indict, strict=True)[source]

Bases: Analyze

Analyze class for handling trajectory density profile calculation

default_params = {'command': 'density', 'console-input': ['0'], 'gromacs': {'gmx': 'gmx'}, 'links': ['postsim/equilibrate/equilibrate.tpr', 'postsim/equilibrate/equilibrate.trr'], 'options': {'b': 0, 'd': 'Z', 'f': 'equilibrate.trr', 'o': 'density.xvg', 's': 'equilibrate.tpr', 'sl': 50, 'xvg': 'none'}, 'subdir': 'analyze/density'}
class HTPolyNet.analyze.AnalyzeFFV(indict, strict=True)[source]

Bases: Analyze

default_params = {'command': 'freevolume', 'gromacs': {'gmx': 'gmx'}, 'links': ['postsim/equilibrate/equilibrate.tpr', 'postsim/equilibrate/equilibrate.trr'], 'matchlines': ['Free volume', 'Total volume', 'Number of molecules', 'Average molar mass', 'Density', 'Molecular volume Vm assuming homogeneity:', 'Molecular van der Waals volume assuming homogeneity:', 'Fractional free volume'], 'options': {'b': 0.0, 'f': 'equilibrate.trr', 'o': 'ffv.xvg', 's': 'equilibrate.tpr', 'xvg': 'none'}, 'outfile': 'ffv.dat', 'subdir': 'analyze/freevolume'}
HTPolyNet.analyze.analyze(args)[source]

postsim handles the analyze subcommand for managing gromacs-based trajectory analyses

Parameters:

args (argparse.Namespace) – command-line arguments

HTPolyNet.banner.banner(logf)[source]
class HTPolyNet.bondlist.Bondlist[source]

Bases: object

The member “B” is a dictionary keyed on atom index whose values of lists of atom indices indicating bond partners of the key atom

adjacency_matrix()[source]

adjacency_matrix generate and return an adjacency matrix built from the bondlist

Returns:

_description_

Return type:

_type_

append(pair)[source]

append appends the bonded pair in parameter ‘pair’ to the bondlist

Parameters:

pair (list-like container) – pair atom indices

are_bonded(idx, jdx)[source]

are_bonded returns True if atoms with indices idx and jdx are bonded neighbors

Parameters:
  • idx (int) – atom index

  • jdx (int) – another atom index

Returns:

True if idx and jdx are bonded neighbors

Return type:

bool

as_list(root, depth)[source]

as_list recursively build a list of all atoms that form a bonded cluster by traversing maximally depth bonds

Parameters:
  • root (list-like container of two ints) – root bond

  • depth (int) – number of bonds to traverse to define bonded cluster

Returns:

list of atom indices in the bonded cluster

Return type:

list

delete_atoms(idx)[source]

delete_atoms deletes all instances of atoms in the list idx from the bondlist

Parameters:

idx (list) – list of indices for atoms to delete

classmethod fromDataFrame(df: DataFrame)[source]
graph()[source]

graph generate a networkx Graph object from the bondlist

Returns:

a networkx Graph object

Return type:

networkx.Graph

half_as_list(root, depth)[source]

half_as_list returns bonded cluster defined by atom b in root found by traversing depth bonds excluding the bond to atom a in root

Parameters:
  • root (list-like container of two ints) – root bond

  • depth (int) – number of bonds to traverse

Returns:

list of atom indices in bonded cluster “owned” by atom b not containing atom a

Return type:

list

partners_of(idx)[source]

partners_of returns a copy of the value of self.B[idx]

Parameters:

idx (int) – atom index

Returns:

list of indices of atoms to which atom ‘idx’ is bound

Return type:

list

update(df: DataFrame)[source]

update updates the bondlist using data in the parameter dataframe df

Parameters:

df (pd.DataFrame) – dataframe with minimally columns named ‘ai’ and ‘aj’

Raises:

Exception – if no column ‘ai’ or ‘aj’ in df

class HTPolyNet.bondtemplate.BondTemplate(names, resnames, intraresidue, order, bystander_resnames, bystander_atomnames, oneaway_resnames, oneaway_atomnames)[source]

Bases: object

is_reverse_of(other)[source]

is_reverse_of return True if self and other are reverse of each other

Parameters:

other (BondTemplate) – another BondTemplate object

Returns:

True if self and other are reverse copies of each other

Return type:

bool

reverse()[source]

reverse the order of all parallel lists in a BondTemplate object

class HTPolyNet.bondtemplate.ReactionBond(idx, resids, order, bystanders, bystanders_atomidx, oneaways, oneaways_atomidx)[source]

Bases: object

reverse()[source]
class HTPolyNet.checkpoint.Checkpoint(input_dict={})[source]

Bases: object

default_filename = 'checkpoint_state.yaml'
classmethod from_yaml()[source]
to_yaml()[source]
HTPolyNet.checkpoint.enableCheckpoint(method)[source]

enableCheckpoint wraps any method so that every call is registered in a history of calls in a written checkpoint file

Parameters:

method (method) – name of method to be wrapped

Returns:

wrapped method

Return type:

method

HTPolyNet.checkpoint.read_checkpoint()[source]

read_checkpoint creates a new global Checkpoint object by reading from the default file

Returns:

current results dictionary with any pathnames resolved as absolute

Return type:

dict

class HTPolyNet.command.Command(command, **options)[source]

Bases: object

linelen = 55
run(override=(), ignore_codes=[], quiet=True)[source]
class HTPolyNet.configuration.Configuration[source]

Bases: object

NewMolecule(mol_name, molrec={})[source]

NewMolecule generate and return a new Molecule object with name mol_name and populated via directives in molrec

Parameters:
  • mol_name (str) – name of new molecule

  • molrec (dict, optional) – dictionary of new molecule directives, defaults to {}

Returns:

the new Molecule object

Return type:

Molecule

Title

List of (Molecule, count)

calculate_maximum_conversion()[source]

calculate_maximum_conversion calculates the maximum number of polymerization bonds that can form based on specified system composition and reactions

constituents

Molecule

Type:

Dictionary of name

default_directives = {'CURE': {}, 'Title': 'No title provided', 'ambertools': {}, 'constituents': {}, 'densification': {}, 'gromacs': {}, 'postcure': {}, 'precure': {}, 'reactions': []}
initial_composition

raw dict read from JSON/YAML

molecules: dict[str, Molecule]

List of Reaction instances

parse(**kwargs)[source]

parse self.basedict to set Title, initial_composition, and lists of reactions and molecules.

reactions: list[Reaction]

all other parameters in cfg file

classmethod read(filename, parse=True, **kwargs)[source]

read generates a new Configuration object by reading in the JSON or YAML file indicated by filename

Parameters:
  • filename (str) – name of file from which to read new Configuration object

  • parse (bool, optional) – if True, parse the input configuration file, defaults to True

Raises:

Exception – if extension of filename is not ‘.json’ or ‘.yaml’ or ‘.yml’

Returns:

a new Configuration object

Return type:

Configuration

class HTPolyNet.coordinates.Coordinates(name='')[source]

Bases: object

Handles atom coordinates.

The primary object is A, a pandas DataFrame with one row per atom. Each atom has attributes that may be found in a gro file and/or a mol2 file, along with so-called extended attributes, which are used solely by HTPolyNet.

add_length_attribute(bdf, attr_name='length')[source]

add_length_attribute computes bond lengths based on bonds indicated by the parallel ‘ai’ and ‘aj’ columns of the parameter dataframe bdf and stores result in a new column called attr_name

Parameters:
  • bdf (pd.DataFrame) – a pandas dataframe with ‘ai’ and ‘aj’ columns of atom indices indicating bonds

  • attr_name (str, optional) – name of length attribute column, defaults to ‘length’

atomcount()[source]

atomcount returns the number of atoms in the Coordinates object

Returns:

number of atoms

Return type:

int

checkbox()[source]

checkbox checks that the entire constellation of points in the atoms dataframe fits within the designated box for this Configuration object

Returns:

True,True if both lower-leftmost and upper-rightmost points are within the box

Return type:

tuple(bool,bool)

claim_parent(parent)[source]
copy_coords(other)[source]

copy_coords copy_coords copy the posX, posY, and posZ atom attributes, and the box size, from other.A to self.A

Parameters:

other (Coordinates) – the other Coordinates instance

decrement_z(pairs)[source]

decrement_z decrements value of z attributes of all atoms found in pairs

Parameters:

pairs (list of 2-tuples) – list of atom index pairs, interpreted as new bonds that just formed

delete_atoms(idx=[], reindex=True)[source]

delete_atoms Deletes atoms whose global indices appear in the list idx. If parameter ‘reindex’ is true, then the global indices are recalculated so that they are sequential starting at 1 with no gaps, and two new columns are added to self.DF: ‘oldGlobalIdx’ contains the global index values before the deletion, and ‘globalIdxShift’ is the change from the old to the new global index for each atom.

Parameters:
  • idx (list, optional) – list of atom indexes to delete, defaults to []

  • reindex (bool, optional) – reindex remaining atoms, defaults to True

classmethod fcc(a, nc=[1, 1, 1])[source]

fcc generates a Coordinates object that represents an FCC crystal

Parameters:
  • a (float) – lattice parameter

  • nc (list, optional) – number of unit cells in the three lattice vector directions, defaults to [1,1,1]

Returns:

a Coordinates object

Return type:

Coordinates

find_sacrificial_H(pairs, T, rename=False, explicit_sacH={})[source]

find_sacrificial_H identifies all appropriate sacrificial hydrogen atoms determined by the bonds indicated in the pairs list of 3-tuples (ai,aj,order)

Parameters:
  • pairs (tuple(int,int,int)) – list of atom pairs/order tuples

  • T (Topology) – the global Topology

  • rename (bool, optional) – If true, renames any remaining H atoms so that it appears as though highest-order named H atoms are the ones sacrificed, defaults to False

  • explicit_sacH (dict, optional) – dictionary of pre-chosen sacrificial H atoms, keyed by pair index, defaults to {}

Returns:

list of global atom indices to delete

Return type:

list

geometric_center()[source]

geometric_center computes and returns the geometric center of the atoms in self’s A dataframe

Returns:

geometric center

Return type:

np.ndarray(3,float)

get_R(idx)[source]

get_R return the cartesian position of atom with global index idx

Parameters:

idx (int) – global index of atom

Returns:

its cartesian position

Return type:

numpy.ndarray(3,float)

get_atom_attribute(name, attributes)[source]

get_atom_attribute return values of attributes listed in name from atoms specified by attribute:value pairs in attributes

Parameters:
  • name (list) – list of attributes whose values are to be returned

  • attributes (dict) – dictionary of attribute:value pairs that specify the set of atoms to be considered

Returns:

scalar or list of one or more return attribute values

Return type:

list if name is a list; scalar otherwise

get_atoms_w_attribute(name, attributes)[source]

get_atoms_w_attribute returns all rows of atoms dataframe and columns named in names of atoms identified by the attributes dict

Parameters:
  • name (list) – list of attributes to be in the rows that are returned

  • attributes (dict) – dictionary of attribute:value pairs that specify the set of atoms to be considered

Returns:

a dataframe segment

Return type:

pd.DataFrame

get_idx(attributes)[source]

get_idx returns the global atom index of the atom in the atoms dataframe which has the attribute:value pairs indicated in the parameter attributes

Parameters:

attributes (dict) – dictionary of attribute:value pairs that identify the atom

Returns:

global atom index

Return type:

int

gro_attributes = ['resNum', 'resName', 'atomName', 'globalIdx', 'posX', 'posY', 'posZ', 'velX', 'velY', 'velZ']

GRO format atom attributes

  • ‘resNum’ unique index of residue to which atom belongs

  • ‘resName’ name of that residue (usually a 3-letter designation)

  • ‘atomName’ name of this atom, must be unique within a residue

  • ‘globalIdx’ global index of atom in whole system

  • ‘posX’, ‘posY’, ‘posZ’ cartesian coordinates

  • ‘velX’, ‘velY’, ‘velZ’ cartesian velocities

has_atom_attributes(attributes)[source]

has_atom_attributes returns True if all atoms in atoms dataframe have the attribute named in attributes

Parameters:

attributes (list or list-like container) – list of attribute names to look for

Returns:

True if all atoms have the attributes

Return type:

bool

homog_trans(M: Matrix4, indices=[])[source]

applies homogeneous transformation matrix M [4x4] to coordinates

Parameters:

M (Matrix4) – homogeneous transformation matrix

linkcell_initialize(cutoff=0.0, ncpu=1, populate=True, force_repopulate=False, save=True)[source]

linkcell_initialize initializes link-cell structure for ring-pierce testing

Parameters:
  • cutoff (float, optional) – cutoff radius for link-cell structure, defaults to 0.0

  • ncpu (int, optional) – number of cpus to use to populate link-cell structure, defaults to 1

  • populate (bool, optional) – If True, an actual population of the link-cell structure is performed; defaults to True

  • force_repopulate (bool, optional) – If True and this link-cell structure is already populated, a repopulation is performed based on the current Coordinates; defaults to False

  • save (bool, optional) – If true, all atoms’ linkcell_idx attributes are written to an output file; defaults to True

linkcelltest(i, j)[source]
linkcelltest returns True if atoms i and j are within potential interaction

range based on current link-cell structure

Parameters:
  • i (int) – An atom index

  • j (int) – another atom index

Returns:

True if i and j are in the same cell or in neighboring cells

Return type:

bool

maxspan()[source]

Returns dimensions of orthorhombic convex hull enclosing Coordinates

Returns:

array of x-span, y-span, z-span

Return type:

numpy.ndarray

merge(other)[source]

merge Merge two Coordinates objects

Parameters:

other (Coordinates) – the other Coordinates object

Returns:

integer shifts in atom index, bond index, and residue index as a 3-tuple

Return type:

tuple

mic(r, pbc)[source]

mic applies minimum image convention to displacement vector r

Parameters:
  • r (np.ndarray(3,float)) – displacement vector

  • pbc (_type_) – periodic boundary condition

Returns:

_description_

Return type:

_type_

minimum_distance(other, self_excludes=[], other_excludes=[])[source]

minimum_distance Computes and returns distance of closest approach between two sets of atoms

Parameters:
  • other (Coordinates) – other Coordinates instance

  • self_excludes (list, optional) – list of atom indexes in self to NOT consider, defaults to []

  • other_excludes (list, optional) – list of atom indexes in other to NOT consider, defaults to []

Returns:

distance of closest approach: i.e., the distance between the two atoms, one from self and one from other, that are closest together

Return type:

float

minmax()[source]

minmax returns the coordinates of the atoms at the lower-leftmost and upper-rightmost positions in the constellation of points in the atoms dataframe

Returns:

tuple of two points, lower-leftmost and upper-rightmost, respectively

Return type:

tuple(np.ndarray(3,float),np.ndarray(3,float))

mol2_atom_attributes = ['globalIdx', 'atomName', 'posX', 'posY', 'posZ', 'type', 'resNum', 'resName', 'charge']

MOL2 format atom attributes

  • ‘globalIdx’ global index of atom in whole system

  • ‘atomName’ name of this atom, must be unique within a residue

  • ‘posX’, ‘posY’, ‘posZ’ cartesian coordinates

  • ‘resNum’ unique index of residue to which atom belongs

  • ‘resName’ name of that residue (usually a 3-letter designation)

  • ‘charge’ charge on atom

mol2_bond_attributes = ['bondIdx', 'ai', 'aj', 'order']
mol2_bond_types = {'ai': <class 'int'>, 'aj': <class 'int'>, 'bondIdx': <class 'int'>, 'order': <class 'str'>}
pierces(B: DataFrame, C: DataFrame, pbc)[source]

pierces determines whether or not bond represented by two points in B pierces ring represented by N points in C

Parameters:
  • B (pd.DataFrame) – two points defining a bond

  • C (pd.DataFrame) – N points defining a ring

  • pbc (list) – periodic boundary condition flags, one per dimension

Returns:

True if ring is pierced

Return type:

bool

read_atomset_attributes(filename, attributes=[])[source]

Reads atomic attributes from input file

Parameters:
  • filename (str) – name of file

  • attributes (list, optional) – list of attributes to take, defaults to [] (take all)

classmethod read_gro(filename, wrap_coords=True)[source]

read_gro Read a Gromacs gro file

Parameters:

filename (str) – name of gro file

Returns:

a new Coordinates instance

Return type:

Coordinates

classmethod read_mol2(filename)[source]
read_mol2 Reads in a Sybyl MOL2 file into a Coordinates instance.

Note that this method only reads in MOLECULE, ATOM, and BOND sections.

Parameters:

filename (str) – name of input mol2 file

Returns:

a new Coordinates instance

Return type:

Coordinates

reconcile_subcoords(subc, attr)[source]

moves all values of attribute name contained in attr from Coordinates object subc to self

Parameters:
  • subc (Coordinates) – A separate, independent Coordinates object

  • attr (str) – attribute name whose value is to be copied from subc to self

return_bond_lengths(bdf)[source]

return_bond_lengths returns an ordered list of bond lengths computed based on bonds indicated by the parallel ‘ai’ and ‘aj’ columns of the parameter dataframe bdf

Parameters:

bdf (pd.DataFrame) – a pandas dataframe with ‘ai’ and ‘aj’ columns of atom indices indicating bonds

Returns:

list of atom distances

Return type:

list

rij(i, j, pbc=[1, 1, 1])[source]

rij compute distance between atoms i and j

Returns:

distance between i and j

Return type:

float

rotate(R)[source]

rotate Rotates all coordinate vectors by rotation matrix R

Parameters:

R (numpy.ndarray) – rotation matrix (3x3)

sacH(ai, aj, T, rename=False)[source]

sacH Find the two H’s, one bound to ai, the other to aj, that are closest to each other

Parameters:
  • ai (int) – index of one atom in bond

  • aj (int) – index of other atom in bond

  • T (Topology) – global topology

  • rename (bool, optional) – whether to rename remaining H atoms bound to ai and aj so that it appears highest-sorted by name atoms are found, defaults to False

Returns:

global indexes of two H atoms

Return type:

list

set_atom_attribute(name, value, attributes)[source]

set_atom_attribute set the attributes named in name to values named in values (names||values) for the set of atoms specified in the attributes dict

Parameters:
  • name (list) – list of names of attributes

  • value (list) – list of values of attributes to be set

  • attributes (dict) – dictionary of attribute:value pairs that specify the set of atoms to be considered

set_atomset_attribute(attribute, srs)[source]

set_atomset_attribute sets attribute of atoms to srs

Parameters:
  • attribute (str) – name of attribute

  • srs (scalar or list-like) – scalar or list-like attribute values in same ordering as self.A

set_box(box: ndarray)[source]

set_box Set the box size from box

Parameters:

box (numpy.ndarray) – 3-by-1 or 3-by-3 box size matrix

show_z_report()[source]

show_z_report generates a little text-based histogram displaying number of atoms with each value of z between 0 and 3; atoms are keyed by resname:atomname.

spew_atom(attributes)[source]

spew_atom outputs all attributes of atom identified by the attributes dict

Parameters:

attributes (dict) – dictionary of attribute:value pairs that specify the set of atoms to be considered

Returns:

stringified dataframe

Return type:

string

subcoords(sub_adf: DataFrame)[source]

subcoords generates a new Coordinates object to hold the atoms dataframe in ‘sub_adf’ parameter

Parameters:

sub_adf (pd.DataFrame) – an atom dataframe

Returns:

a new Coordinates object

Return type:

Coordinates

total_volume(units='gromacs')[source]

Returns total volume of box.

Parameters:

units (str, optional) – unit system designation; if ‘SI’ returns m^3, defaults to ‘gromacs’

Returns:

volume (in nm^3 if units is ‘gromacs’ or m^3 if units is ‘SI’)

Return type:

float

translate(L)[source]

translate Translates all coordinate vectors by displacement vector L

Parameters:

L (numpy.ndarray) – displacement vector (nm)

unwrap(P, O, pbc)[source]

unwrap shifts point P to its unwrapped closest periodic image to point O

Parameters:
  • P (np.ndarray(3,float)) – a point

  • O (np.ndarray(3,float)) – origin

  • pbc (np.ndarray(3,int)) – directions in which pbc are applied

Returns:

a point

Return type:

nd.ndarray(3,float)

wrap_coords()[source]

wrap_coords Wraps all atomic coordinates into box

wrap_point(ri)[source]

wrap_point wraps point ri into the central periodic image

Parameters:

ri (np.ndarray(3,float)) – a point

Returns:

a tuple containing (1) the wrapped point and (2) number of box lengths required to wrap this point, per dimension

Return type:

tuple

write_atomset_attributes(attributes, filename, formatters=[])[source]

write_atomset_attributes Writes atom attributes to a file

Parameters:
  • attributes (list, optional) – List of attribute names to write

  • filename (str) – Name of file to write

  • formatters (list) – formatting methods per attribute, defaults to []

Raises:

Exception – All items in attributes must exist in the coordinates dataframe

write_gro(filename, grotitle='')[source]

write_gro Write coordinates and if present, velocities, to a Gromacs-format coordinate file

Parameters:

filename (str) – name of file to write

write_mol2(filename, bondsDF=Empty DataFrame Columns: [] Index: [], molname='', other_attributes=Empty DataFrame Columns: [] Index: [])[source]
write_mol2 Write a mol2-format file from coordinates, and optionally, a bonds DataFrame

provided externally and passed in as “bondsDF” (typically this would be from a Topology instance).

Parameters:
  • filename (str, optional) – name of file name to write

  • bondsDF (pandas.DataFrame, optional) – dataframe of bonds [‘ai’,’aj’], defaults to pd.DataFrame()

  • molname (str, optional) – name of molecule, defaults to ‘’

  • other_attributes (pandas.DataFrame, optional) – auxiliary dataframe of attributes, defaults to pd.DataFrame()

HTPolyNet.coordinates.GRX_ATTRIBUTES = ['z', 'nreactions', 'reactantName', 'sea_idx', 'bondchain', 'bondchain_idx', 'molecule', 'molecule_name']

Extended atom attributes

  • ‘z’ number of sacrificial H’s on atom

  • ‘nreactions’ number of H’s sacrificed so far to form bonds

  • ‘reactantName’ name of most recent reactant to which atom belonged

  • ‘sea_idx’ index of the group of symmetry-related atoms this atom belongs to (atoms with the same sea_idx in the same resid are considered symmetry-equivalent)

  • ‘bondchain’ index of the unique bondchain this atom belongs to; a bondchain is a continuous linear chain of C-C bonds

  • ‘bondchain_idx’ index of this atom within this chain

  • ‘molecule’ index of the unique molecule this atom belongs to

  • ‘molecule_name’ name of that molecule

HTPolyNet.coordinates.dfrotate(df: DataFrame, R)[source]

dfrotate applies rotation matrix R to coordinates in dataframe

Parameters:
  • df (pd.DataFrame) – coordinates dataframe; must have ‘posX’, ‘posY’, and ‘posZ’ columns

  • R (np.ndarray((3,3))) – rotation matrix

HTPolyNet.countTime.countTime(fn)[source]
class HTPolyNet.curecontroller.CureController(curedict={})[source]

Bases: object

curedict_defaults = {'controls': {'desired_conversion': 0.5, 'late_threshold': 0.85, 'max_conversion_per_iteration': 1.0, 'max_iterations': 100, 'min_allowable_bondcycle_length': -1, 'ncpu': 4, 'radial_increment': 0.05, 'search_radius': 0.5}, 'drag': {'cutoff_pad': 0.2, 'equilibration': [{'ensemble': 'min'}, {'ensemble': 'nvt', 'nsteps': 1000, 'temperature': 600}, {'ensemble': 'npt', 'nsteps': 2000, 'pressure': 1, 'temperature': 600}], 'increment': 0.0, 'kb': 300000.0, 'limit': 0.0, 'nstages': 0, 'trigger_distance': 0.0}, 'equilibrate': {'ensemble': 'npt', 'nsteps': 50000, 'pressure': 1, 'temperature': 300}, 'gromacs': {'rdefault': 0.9}, 'output': {'bonds_file': 'bonds.csv'}, 'relax': {'cutoff_pad': 0.2, 'equilibration': [{'ensemble': 'min'}, {'ensemble': 'nvt', 'nsteps': 1000, 'temperature': 600}, {'ensemble': 'npt', 'nsteps': 2000, 'pressure': 1, 'temperature': 600}], 'increment': 0.0, 'nstages': 6}}
default_equilibration_sequence = [{'ensemble': 'min'}, {'ensemble': 'nvt', 'nsteps': 1000, 'temperature': 600}, {'ensemble': 'npt', 'nsteps': 2000, 'pressure': 1, 'temperature': 600}]
do_capping(TC: TopoCoord, RL: list[Reaction], MD: dict[str, Molecule], gromacs_dict={})[source]

do_capping manages generation of all capping bonds

Parameters:
  • TC (TopoCoord) – TopoCoord object containing all topology and coordinate information

  • RL (ReactionList) – ReactionList object containing all reaction types

  • MD (MoleculeDict) – MoleculeDict object containing all molecule information

  • gromacs_dict (dict, optional) – dictionary of custom gromacs parameters, defaults to {}

Returns:

dictionary of resulting output files, keyed by extension (‘gro’, ‘top’, ‘grx’)

Return type:

dict

do_iter(TC: TopoCoord, RL: list[Reaction], MD: dict[str, Molecule], gromacs_dict={})[source]

do_iter performs one CURE iteration

Parameters:
  • TC (TopoCoord) – TopoCoord object; all topological and coordinate information is in here

  • RL (ReactionList) – ReactionList object; list of all reaction types

  • MD (MoleculeDict) – MoleculeDict object; dictionary of all molecules, keyed by name

  • gromacs_dict (dict, optional) – dictionary of custom gromacs parameters, defaults to {}

Returns:

dictionary of resulting output file names

Return type:

dict

is_cured()[source]

is_cured returns True if system is cured

Returns:

True if system is cured; False otherwise

Return type:

bool

next_iter()[source]

next_iter resets this CureController for the next CURE iteration

Returns:

True if new iteration index exceeds the maximum number of iterations allowed by runtime

Return type:

bool

reset()[source]

reset resets this CureController object by resetting its CureState, its bonds dataframe, and its search_failed member

setup(max_nxlinkbonds=0, desired_nxlinkbonds=0, max_search_radius=0.0)[source]

setup sets up this CureController object

Parameters:
  • max_nxlinkbonds (int, optional) – maximum allowable number of bonds, defaults to 0

  • desired_nxlinkbonds (int, optional) – desired number of bonds, defaults to 0

  • max_search_radius (float, optional) – maximum search radius (nm), defaults to 0.0

class HTPolyNet.curecontroller.CureState[source]

Bases: object

classmethod from_yaml(filename='cure_state.yaml')[source]

from_yaml returns a new CureState object generated by reading in the YAML file

Parameters:

filename (str, optional) – input file name, defaults to ‘cure_state.yaml’

Returns:

new CureState object returned by yaml.load

Return type:

CureState

reset()[source]

reset resets this CureState object to begin a new CURE iteration

class HTPolyNet.curecontroller.cure_step(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumerated CURE step

basename()[source]
cap_bondsearch = 5
cap_equilibrate = 8
cap_relax = 7
cap_update = 6
cure_bondsearch = 0
cure_drag = 1
cure_equilibrate = 4
cure_relax = 3
cure_update = 2
finished = 9
unknown = 99
HTPolyNet.dataframetools.get_row(df: DataFrame, attributes: dict)[source]

return a pandas Series of the row that matches the attribute dict

HTPolyNet.dataframetools.get_row_as_string(df: DataFrame, attributes)[source]
get_row_as_string returns a scalar value of attribute “name” in row

expected to be uniquely defined by attributes dict

Parameters:
  • df (pd.DataFrame) – a pandas dataframe

  • attributes (dict(str,obj)) – dictionary of column names (keys) and values that specify set of rows to be returned

Returns:

selected dataframe converted to a string

Return type:

str

HTPolyNet.dataframetools.get_row_attribute(df: DataFrame, name, attributes)[source]
get_row_attribute returns a scalar value of attribute “name” in row

expected to be uniquely defined by attributes dict

Parameters:
  • df (pandas.DataFrame) – dataframe to search

  • name (str) – name of attribute whose value you want

  • attributes (dict) – dictionary of attribute:value pairs that defines target set or row

Returns:

value of attribute name

Return type:

scalar

HTPolyNet.dataframetools.get_rows_w_attribute(df: DataFrame, name, attributes: dict)[source]
HTPolyNet.dataframetools.set_row_attribute(df: DataFrame, name, value, attributes)[source]

set_row_attribute set value of attribute name to value in all rows matching attributes dict

Parameters:
  • df (pd.DataFrame) – a pandas dataframe

  • name (str) – name of attribute whose value is to be set

  • value (scalar) – value the attribute is to be set to

  • attributes (dict) – dictionary of attribute:value pairs that specify the atoms whose attribute is to be set

HTPolyNet.dataframetools.set_rows_attributes_from_dict(df: DataFrame, valdict, attributes)[source]
set_rows_attributes_from_dict set values of attributes in valdict dict of all rows

matching attributes dict

Parameters:
  • df (pd.DataFrame) – a pandas dataframe

  • valdict (dict) – dictionary of attribute:value pairs to set

  • attributes (dict) – dictionary of attribute:value pairs that specify the atoms whose attribute is to be set

HTPolyNet.expandreactions.bondchain_expand_reactions(molecules: dict[str, Molecule])[source]

bondchain_expand_reactions handles generation of new reactions and molecular templates implied by any C-C bondchains

Note

must be called after all grx attributes are set for all molecules

param molecules:

dictionary of molecular templates constructed from explicit declarations

type molecules:

MoleculeDict

return:

the list of new reactions and dictionary of new molecules

rtype:

tuple(ReactionList,MoleculeDict)

HTPolyNet.gromacs.get_energy_menu(edr, **kwargs)[source]

get_energy_menu gets the menu provided by ‘gmx energy’ when applied to a particular edr file

Parameters:

edr (str) – name of edr file

Returns:

menu dictionary

Return type:

dict

HTPolyNet.gromacs.gmx_command(name, options={}, console_in='')[source]
HTPolyNet.gromacs.gmx_energy_trace(edr, names=[], report_averages=False, keep_files=False, **kwargs)[source]

Generate traces of data in edr file

Parameters:
  • edr (str) – name of edr file

  • names (list) – list of data names, defaults to []

  • report_averages (bool, optional) – flag to indicate if averages of all data are to be computed here, default False

  • keep_files (bool) – flag indicating caller would like to keep the raw input and output files for gmx energy, default False

Returns:

dataframe of traces

Return type:

pandas DataFrame

HTPolyNet.gromacs.gmx_traj_info(trr)[source]
HTPolyNet.gromacs.gro_from_trr(pfx, nzero=2, b=0, outpfx='')[source]
HTPolyNet.gromacs.gromacs_distance(idf, gro, new_column_name='r', pfx='tmp', force_recalculate=False, keep_files=False)[source]

Use ‘gmx distance’ to measure interatomic distances

Parameters:
  • idf (pandas DataFrame) – dataframe of atom indexes in pairs [‘ai’,’aj’]

  • gro (str) – name of gromacs input file for ‘gmx distance’ to use

  • new_column_name (str, optional) – name of column in idf where distances are stored, default ‘r’

  • force_recalculate (boolean, optional) – flag to force calculation of distances even if a distance column exists in idf, default False

  • keep_files (bool, optional) – flag indicating caller would like to keep the raw input and output files for gmx energy default False

Returns:

list of distances parallel to idf columns

Return type:

numpy.ndarray

HTPolyNet.gromacs.grompp_and_mdrun(gro='', top='', out='', mdp='', boxSize=[], single_molecule=False, **kwargs)[source]

grompp_and_mdrun launcher for grompp and mdrun

Parameters:
  • gro (str, optional) – input gro file, defaults to ‘’

  • top (str, optional) – input top file, defaults to ‘’

  • out (str, optional) – output file basename, defaults to ‘’

  • mdp (str, optional) – input mdp file, defaults to ‘’

  • boxSize (list, optional) – explicit box size, defaults to []

  • single_molecule (bool, optional) – if true, a single-molecule system is simulated, defaults to False

HTPolyNet.gromacs.insert_molecules(composition, boxSize, outName, inputs_dir='.', **kwargs)[source]

insert_molecules launcher for gmx insert-molecules

Parameters:
  • composition (dict) – dictionary of molecule_name:count

  • boxSize (list(3,float) or float) – size of box as 3 floats or 1 float (if cubic box)

  • outName (str) – basename of output files

  • inputs_dir (str, optional) – directory to search for input structures, defaults to ‘.’

Raises:

Exception – if gmx-insert molecules fails to insert the requested number of molecules

HTPolyNet.gromacs.mdp_get(mdp_filename, key)[source]
HTPolyNet.gromacs.mdp_modify(mdp_filename, opt_dict, new_filename=None, add_if_missing=True)[source]

Modify a gromacs mdp file

Parameters:
  • mdp_filename (str) – name of mdp file to modify; overwritten if new_filename==None

  • opt_dict (dict) – keyword:value dictionary of mdp options

  • new_filename (str, optional) – name of outputile, defaults to None

  • add_if_missing (bool, optional) – Flag indicating whether to insert key:value into mdp file if not already there, defaults to True

HTPolyNet.gromacs.mdp_to_dict(mdp_filename)[source]
HTPolyNet.inputcheck.input_check(args)[source]

input_check manages in the input-check subcommand

Parameters:

args (argparse.Namespace) – parsed arguments

class HTPolyNet.linkcell.Linkcell(box=[], cutoff=None, pbc_wrapper=None)[source]

Bases: object

Handles the link-cell algorithm for searching for bonding partners within a cutoff distance from each other

are_cellndx_neighbors(Ci, Cj)[source]

are_cellndx_neighbors returns True if cells with (i,j,k) indices Ci and Cj are neighbors

Parameters:
  • Ci (np.ndarray(3,int)) – cell index

  • Cj (np.ndarray(3,int)) – cell index

Returns:

True if cells are neighbors, False otherwise

Return type:

bool

are_ldx_neighbors(ildx, jldx)[source]

are_ldx_neighbors returns True if cells with scalar indices ildx and jldx are neighbors

Parameters:
  • ildx (int) – scalar cell index

  • jldx (int) – scalar cell index

Returns:

True if cells are neighbors, False otherwise

Return type:

bool

cellndx_in_structure(C)[source]

cellndx_in_structure test to see if (i,j,k) index given is within the established linkcell structure

Parameters:

C ((int,int,int)) – (i,j,k) index

Returns:

  • True: C is in the linkcell structure

  • False: C is not in the linkcell structure

Return type:

boolean

cellndx_of_ldx(i)[source]

cellndx_of_ldx returns (i,j,k)-index of cell with scalar index i

Parameters:

i (int) – scalar cell index

Returns:

(i,j,k)-index of cell

Return type:

(int,int,int)

cellndx_of_point(R)[source]

cellndx_of_point returns the (i,j,k) cell index of point R

Parameters:

R (numpy.ndarray) – a 3-space point

Returns:

(i,j,k) index of cell

Return type:

(int,int,int)

corners_of_cellndx(C)[source]

corners_of_cellndx returns the lower-left and upper-right corners of cell with (i,j,k) index C, as an array of 3-space points

Parameters:

C ((int,int,int)) – (i,j,k) index

Returns:

2x3 array of lower-left and upper-right corner coordinates

Return type:

numpy.ndarray

create(cutoff, box, origin=array([0., 0., 0.]))[source]

create Creates the link-cell structure in a previously initialized instance

Parameters:
  • cutoff (float) – cutoff distance

  • box (numpy.ndarray) – box size

  • origin (numpy.ndarry, optional) – origin, defaults to np.array([0.,0.,0.])

ldx_of_cellndx(C)[source]

ldx_of_cellndx return scalar index of cell with (i,j,k)-index C

Parameters:

C ((int,int,int)) – (i,j,k)-index

Returns:

scalar index of C

Return type:

int

make_memberlists(cdf)[source]

make_memberlists populates the memberlists member, one element per cell; each element is the list of atom indices in that cell

Parameters:

cdf (pd.DataFrame) – coordinates data frame

make_neighborlists()[source]

make_neighborlists populates the neighborlist member, one element per cell; each element is the list of neighbors of that cell

neighbors_of_cellndx(Ci)[source]

neighbors_of_cellndx returns the list of neighbors of cell Ci by their (i,j,k) indices

Parameters:

Ci (_type_) – _description_

Returns:

_description_

Return type:

_type_

point_in_cellndx(R, C)[source]

point_in_cellndx returns True if point R is located in cell with (i,j,k) index C

Parameters:
  • R (numpy.ndarray) – 3-space point

  • C ((int,int,int)) – (i,j,k) cell index

Returns:

  • True: R in C

  • False: R not in C

Return type:

boolean

populate(Coordinates, ncpu=1)[source]

populate Populates linkcell structure

Parameters:
  • Coordinates (Coordinates) – Coordinates instance from which atom coordinates are taken

  • ncpu (int, optional) – number of processors to split the operation over, defaults to 1

Raises:

Exception – dies if a point’s assigned (i,j,k) cell is outside the cell structure (this would mean the atom’s position is outside the periodic box, which is an error. Atom coordinates are always to be held in wrapped configuration, but be careful: gro files unwrap!)

populate_par(adf)[source]

populate_par populate the linkcell structure by setting the “linkcell_idx” attribute of each atom in the coordinates dataframe adf

Parameters:

adf (pandas.DataFrame) – gromacs-format coordinate dataframe

Returns:

modified dataframe

Return type:

pandas.DataFrame

searchlist_of_ldx(i)[source]

searchlist_of_ldx returns the list of scalar cell indices of cells that are neighbors of cell with scalar index i

Parameters:

i (int) – scalar cell index

Returns:

list of scalar indices of neighbor cells

Return type:

list

class HTPolyNet.matrix4.Matrix4(*args)[source]

Bases: object

Class for handling 4x4 homogeneous transformation matrices

rot(degrees, axis)[source]

Apply a rotation around a Cartesian axis by a certain number of degrees; right-hand rule applies

rotate_axis(degrees, axis)[source]
transform(point3D)[source]
transinvec(x, y, z)[source]
translate(*args)[source]
transvec(x, y, z)[source]
class HTPolyNet.molecule.Molecule(name='', generator: Reaction = None, origin: str = None)[source]

Bases: object

classmethod New(mol_name, generator: Reaction, molrec={})[source]

New generates a new, partially populated Molecule based on directives in the configuration input

Parameters:
  • mol_name (str) – name of molecule

  • generator (Reaction) – reaction that generates this molecule, if applicable

  • molrec (dict, optional) – dictionary of directive for this molecule, defaults to {}

Returns:

a new Molecule object

Return type:

Molecule

atoms_w_same_attribute_as(find_dict={}, same_attribute='', return_attribute='')[source]

atoms_w_same_attribute_as returns a list of atom attributes named in the return_attribute parameter from atoms that share an attribute named in the same_attribute parameter with the atom identified by the find_dict parameter

Parameters:
  • find_dict (dict, optional) – dictionary of attribute:value pairs that should uniquely identify an atom, defaults to {}

  • same_attribute (str, optional) – name of attribute used to screen atoms, defaults to ‘’

  • return_attribute (str, optional) – attribute value to return a list of from the screened atoms, defaults to ‘’

Returns:

list of attribute values

Return type:

list

center_coords(new_boxsize: ndarray = None)[source]

center_coords wrapper for the TopoCoord.center_coords method

Parameters:

new_boxsize (np.ndarray, optional) – new box size, defaults to None

create_new_stereoisomers()[source]

create_new_stereoisomers generate new molecules to hold stereoisomers of self

Returns:

None if no action taken

Return type:

none

determine_sequence(moldict)[source]

determine_sequence recursively determine the sequence of a molecule using the network of reactions that must be executed to generate it from primitives

Parameters:

moldict (dict) – dictionary of available molecules

Returns:

list of resnames in order of sequence

Return type:

list

flip_stereocenters(idxlist)[source]

flip_stereocenters flips stereochemistry of atoms in idxlist

Parameters:

idxlist (list) – global indices of chiral atoms

generate(outname='', available_molecules={}, **kwargs)[source]

generate manages generating topology and coordinates for self

Parameters:
  • outname (str, optional) – output file basename, defaults to ‘’

  • available_molecules (dict, optional) – dictionary of available molecules, defaults to {}

generate_conformers()[source]

generate_conformers generates this molecule’s conformer instances using either gromacs or obabel

generate_stereoisomers()[source]

generate_stereoisomers generates list of Molecule shells, one for each stereoisomer

Returns:

only returns if no stereoisomers need to be generated

Return type:

None

get_angles_dihedrals(bond)[source]

get_angles_dihedrals returns copies of selections from the Topology interaction-type dataframes that contain the two atoms indicated in the bond

Parameters:

bond (list-like container) – 2-element list-like container of ints

Raises:

Exception – dies if a NaN is found in any selection

Returns:

tuple of the three dataframe selection copies for angles, dihedrals, and 1-4 pairs

Return type:

tuple

get_molecular_weight()[source]

get_molecular_weight returns the molecular weight of self

Returns:

_description_

Return type:

_type_

get_origin()[source]

get_origin returns the value of the origin member

Returns:

value of origin member

Return type:

anything

get_resname(internal_resid)[source]

get_resname returns the residue name at position internal_resid in the molecule’s sequence

Parameters:

internal_resid (int) – molecule-internal residue index

Returns:

residue name

Return type:

str

idx_mappers(otherTC: TopoCoord, other_bond, bystanders, oneaways, uniq_atom_idx: set)[source]

idx_mappers computes the mapping dictionary from molecule template index to instance index in the other TopoCoord

Parameters:
  • otherTC (TopoCoord) – the other TopoCoord

  • other_bond (list-like container of length 2) – 2 atom indices of the bond in the other TopoCoord

  • bystanders (lists) – bystander lists, one for each reacting atom

  • oneaways (list (2)) – oneaways, one for each atom in the bond

  • uniq_atom_idx (set) – set of unique atoms in template that must be mapped to instance

Raises:

Exception – if there is a buggy double-counting of one or more indexes

Returns:

two-way dictionaries of index mappers instance<->template

Return type:

tuple of two dictionaries

initialize_molecule_rings()[source]

initialize_molecule_rings generates the dictionary of rings

the dictionary of rings is keyed on ring size

initialize_monomer_grx_attributes()[source]

initialize_monomer_grx_attributes initializes all GRX attributes of atoms in molecule

load_top_gro(topfilename, grofilename, tpxfilename='', mol2filename='', **kwargs)[source]

load_top_gro generate a new TopoCoord member object for this molecule by reading in a Gromacs topology file and a Gromacs gro file

Parameters:
  • topfilename (str) – Gromacs topology file

  • grofilename (str) – Gromacs gro file

  • tpxfilename (str, optional) – extended topology file, defaults to ‘’

  • mol2filename (str, optional) – alternative coordinate mol2 file, defaults to ‘’

make_bonds(bdf: DataFrame, moldict, stage)[source]

make_bonds adds new bonds to the molecule’s topology and deletes any sacrificial hydrogens

Parameters:
  • bdf (pd.DataFrame) – pandas dataframe identifying new bonds

  • moldict (dict) – dictionary of available molecular templates

  • stage (reaction_stage(Enum)) – enumerated parameter indicating reaction_stage

merge(other)[source]

merge merges TopoCoord from other into self’s TopoCoord

Parameters:

other (Molecule) – another Molecule

Returns:

a shift tuple (returned by Coordinates.merge())

Return type:

tuple

minimize(outname='', **kwargs)[source]

minimize manages invocation of vacuum minimization

Parameters:

outname (str, optional) – output file basename, defaults to ‘’

parameterize(outname='', input_structure_format='mol2', **kwargs)[source]

parameterize manages GAFF parameterization of this molecule

Parameters:
  • outname (str, optional) – output file basename, defaults to ‘’

  • input_structure_format (str, optional) – input structure format, defaults to ‘mol2’ (‘pdb’ is other possibility)

prepare_new_bonds(available_molecules={})[source]

prepare_new_bonds populates the bond templates and reaction bonds for self

Parameters:

available_molecules (dict, optional) – dictionary of available molecules, defaults to {}

previously_parameterized()[source]

previously_parameterized if a gro file exists in the project molecule/parameterized directory for this molecule, return True

Returns:

True if gro file found

Return type:

bool

read_gro_attributes(grxfilename, attribute_list=[])[source]

Read attributes from file into self.TopoCoord.Coordinates.A

Parameters:
  • grxfilename (str) – name of input file

  • attribute_list (list, optional) – list of attributes to take, defaults to [] (take all)

relax(relax_dict)[source]

relax manages invocation of MD relaxations

Parameters:

relax_dict (dict) – dictionary of simulation directives

rotate_bond(a, b, deg)[source]

rotate_bond rotates all atoms in molecule on b-side of a-b bond by deg degrees

Parameters:
  • a (int) – index of a

  • b (int) – index of b

  • deg (float) – angle of rotation (degrees)

set_gro_attribute(attribute, srs)[source]

set_gro_attribute sets attribute of atoms to srs (drillst through to Coordinates.set_atomset_attributes())

Parameters:
  • attribute (str) – name of attribute

  • srs (scalar or list-like) – scalar or list-like attribute values in same ordering as self.A

set_origin(value)[source]

set_origin sets the value of the origin member

Parameters:

value (anything) – value

set_sequence_from_coordinates()[source]

set_sequence Establish the sequence-list (residue names in order) based on resNum attributes in atom list

set_sequence_from_moldict(moldict)[source]

set_sequence_from_moldict set the sequence of this molecule using the recursive determine_sequence method

Parameters:

moldict (dict) – dictionary of available molecules

Returns:

self

Return type:

Molecule

transrot(at_idx, at_resid, from_idx, from_resid, connected_resids=[])[source]

transrot given a composite molecule, translate and rotate the piece downstream of the yet-to-be created bond specified by (at_idx,at_resid) and (from_idx,from_resid) to minimize steric overlaps and identify the best two sacrificial hydrogens

Parameters:
  • at_idx (int) – global index of left-hand atom in new bond

  • at_resid (int) – global index of left-hand residue

  • from_idx (int) – global index of right-hand atom in new

  • from_resid (int) – global index of right-hand residue

  • connected_resids (list, optional) – list of all other resids attached to right-hand residue that should move with it, defaults to []

Returns:

2-tuple containing global indices

Return type:

tuple

update_zrecs(zrecs, moldict)[source]

update_zrecs updates the “z-records” based on z’s declared in the input configuration file

Parameters:
  • zrecs (dict) – zrecs extracted from configuration file for this molecule

  • moldict (dicts) – dictionary of available molecules

write_gro_attributes(attribute_list, grxfilename)[source]

Writes atomic attributes to a file

Parameters:
  • attributes_list (list) – list of attributes to write

  • grxfilename (str) – name of output file

HTPolyNet.molecule.generate_stereo_reactions(RL: list[Reaction], MD: dict[str, Molecule])[source]

generate_stereo_reactions scans the list of reactions and generates any additional reactions in which all possible stereoisomers are reactants

Parameters:
  • RL (ReactionList) – list of Reactions

  • MD (MoleculeDict) – dictionary of available Molecules

Returns:

number of new reactions/molecular products created

Return type:

int

HTPolyNet.molecule.generate_symmetry_reactions(RL: list[Reaction], MD: dict[str, Molecule])[source]

generate_symmetry_reactions scans reaction list to generate any new reactions implied by symmetry-equivalent atoms

Parameters:
  • RL (ReactionList) – list of Reactions

  • MD (MoleculeDict) – dict of available molecules

Returns:

number of new reactions/molecular products created

Return type:

int

HTPolyNet.molecule.yield_bonds(R: Reaction, TC: TopoCoord, resid_mapper)[source]

yield_bonds for each bond pattern in the reaction R, yield the specific bond represented by this pattern in the molecule’s topology

Parameters:
  • R (Reaction) – a Reaction

  • TC (TopoCoord) – molecule topology and coordinates

  • resid_mapper (dict) – dictionary that maps in-reactant resids to in-product resids

Yield:

a reaction bond

Return type:

ReactionBond

HTPolyNet.molecule.yield_bonds_as_df(R: Reaction, TC: TopoCoord, resid_mapper)[source]

yield_bonds_as_df returns a pandas DataFrame identifying all reaction bonds obtained by matching the reaction template bonds to instances in the molecule topology

Parameters:
  • R (Reaction) – a Reaction

  • TC (TopoCoord) – molecule topology and coordinates

  • resid_mapper (dict) – dictionary that maps in-reactant resids to in-product resids

Returns:

dataframe with all reaction bonds

Return type:

pd.DataFrame

HTPolyNet.plot.build_plots(args)[source]
HTPolyNet.plot.diag_plots(args)[source]
HTPolyNet.plot.diagnostics_graphs(logfiles, filename, **kwargs)[source]

diagnostics_graphs extracts selected data from the diagnostic output and generates plots

Parameters:
  • logfiles (list) – list of names of diagnostic log files to treat in parallel

  • filename (str) – name of output image file

HTPolyNet.plot.do_E_plots(phases, projdirs, outfile='e.png', fit_domain=[10, 200], save_data='E.csv')[source]
HTPolyNet.plot.do_tg_plots(phases, projdirs, outfile='tg.png', save_data='data.csv', n_points=[10, 20])[source]
HTPolyNet.plot.global_trace(df, names, outfile='plot.png', transition_times=[], markers=[], interval_labels=[], y2names=[], **kwargs)[source]

global_trace generates custom-formatted multiplots of energy-like quantities named in ‘names’ in the input dataframe df

Parameters:
  • df (pd.DataFrame) – pandas dataframe containing all data

  • names (list) – list of quantity names (Density, Temperature, etc)

  • outfile (str, optional) – name of output image file, defaults to ‘plot.png’

  • transition_times (list, optional) – time values at which vertical lines are drawn, defaults to []

  • markers (list, optional) – time values at which transitions are marked somehow, I forget, defaults to []

  • interval_labels (list, optional) – list of labels of intervals defined by markers, defaults to []

  • y2names (list, optional) – names of quantities to be plotted on a secondary y axis, defaults to []

HTPolyNet.plot.init_molecule_graph(proj_dir)[source]

init_molecule_graph creates and initializes a inter-molecular graph to show network connectivity

Parameters:

proj_dir (str) – name of project directory

Returns:

a nodes-only Graph enumerating all molecules; this will be further processed elsewhere to add connectivity information

Return type:

networkx.Graph

HTPolyNet.plot.multi_trace(dfL, xnames, ynames, labels=[], xlabel='time [ps]', ylabel='', outfile='plot.png', **kwargs)[source]

multi_trace generates a plot of each y vs x in df

Parameters:
  • df (pandas.DataFrame) – a pandas dataframe

  • xnames (list) – list of x-column names

  • ynames (list) – list of y-column names, parallel to xnames

  • outfile (str, optional) – name of output image file, defaults to ‘plot.png’

HTPolyNet.plot.network_graph(G, filename, **kwargs)[source]

network_graph draws a custom formatted network plot from graph G

Parameters:
  • G (nx.Graph or nx.DiGraph) – a graph from networkx

  • filename (str) – name of output image filename

HTPolyNet.plot.plots(args)[source]

plots handles the plots subcommand

Parameters:

args (argparse.Namespace) – command-line arguments

HTPolyNet.plot.post_plots(args)[source]
HTPolyNet.plot.scatter(df, xcolumn, columns=[], outfile='plot.png', **kwargs)[source]

scatter generic scatter plot generator

Parameters:
  • df (pd.DataFrame) – dataframe containing data

  • xcolumn (str) – name of column holding x-data

  • columns (list, optional) – list of y-value columns to be plotted vs. x, defaults to []

  • outfile (str, optional) – name of output image file, defaults to ‘plot.png’

HTPolyNet.plot.trace(qty, edrs, outfile='plot.png', **kwargs)[source]

trace generates a plot of the energy-like quantity named by ‘qty’ vs time by reading data from the list of edr files named in ‘edrs’

Parameters:
  • qty (str) – name of energy-like quantity; must conform to menu generated by ‘gmx energy’

  • edrs (list) – list of names of edr files to scan, in order

  • outfile (str, optional) – name of output image file, defaults to ‘plot.png’

Returns:

the list of average values

Return type:

list

class HTPolyNet.postsim.PostSimAnneal(indict, strict=True)[source]

Bases: PostSimMD

a class to handle temperature annealing MD simulation

build_mdp(mdpname, **kwargs)[source]

build_mdp builds the GROMACS mdp file required for an annealing MD simulation

Parameters:

mdpname (str) – name of mdp file

default_params = {'P': 1, 'T0': 300, 'T0_ps': 1000, 'T0_to_T1_ps': 1000, 'T1': 600, 'T1_ps': 1000, 'T1_to_T0_ps': 1000, 'gromacs': {'gmx': 'gmx', 'mdrun': 'gmx mdrun', 'mdrun_single_molecule': 'gmx mdrun', 'options': '-quiet -nobackup'}, 'input_gro': 'systems/final-results/final.gro', 'input_grx': 'systems/final-results/final.grx', 'input_top': 'systems/final-results/final.top', 'ncycles': 1, 'output_deffnm': 'anneal', 'scatter': ('time(ps)', ['Density'], 'rho_v_ns.png'), 'subdir': 'postsim/anneal', 'traces': ['Temperature', 'Density', 'Volume']}
class HTPolyNet.postsim.PostSimDeform(indict, strict=True)[source]

Bases: PostSimMD

a class to handle a uniaxial deformation MD simulation

build_mdp(mdpname, **kwargs)[source]

build_mdp builds the GROMACS mdp file required for a temperature-ladder MD simulation

Parameters:

mdpname (str) – name of mdp file

default_params = {'P': 1.0, 'T': 300.0, 'direction': 'x', 'edot': 0.001, 'gromacs': {'gmx': 'gmx', 'mdrun': 'gmx mdrun', 'mdrun_single_molecule': 'gmx mdrun mdrun', 'options': '-quiet -nobackup'}, 'input_gro': 'postsim/equilibrate/equilibrate.gro', 'input_grx': 'systems/final-results/final.grx', 'input_top': 'systems/final-results/final.top', 'output_deffnm': 'deform-x', 'ps': 1000, 'scatter': ('Box-X', ['Pres-XX'], 'tension_v_xlength.png'), 'subdir': 'postsim/deform-x', 'traces': ['Box-X', 'Pres-XX']}
class HTPolyNet.postsim.PostSimLadder(indict, strict=True)[source]

Bases: PostSimMD

a class to handle a temperature-ladder MD simulation

build_mdp(mdpname, **kwargs)[source]

build_mdp builds the GROMACS mdp file required for a temperature-ladder MD simulation

Parameters:

mdpname (str) – name of mdp file

default_params = {'P': 1, 'Thi': 600.0, 'Tlo': 300.0, 'deltaT': 5, 'gromacs': {'gmx': 'gmx', 'mdrun': 'gmx mdrun', 'mdrun_single_molecule': 'gmx mdrun mdrun', 'options': '-quiet -nobackup'}, 'input_gro': 'systems/final-results/final.gro', 'input_grx': 'systems/final-results/final.grx', 'input_top': 'systems/final-results/final.top', 'output_deffnm': 'ladder', 'ps_per_rise': 1000, 'ps_per_run': 1000, 'scatter': ('time(ps)', ['Density'], 'rho_v_ns.png'), 'subdir': 'postsim/ladder', 'traces': ['Temperature', 'Density', 'Volume'], 'warmup_ps': 5000}
class HTPolyNet.postsim.PostSimMD(indict, strict=True)[source]

Bases: object

Generic class for handling post-cure md simulations; this one just does simple NPT MD equilibration; Classes that inherit from this class should define their own default_params and build_npt

build_mdp(mdpname, **kwargs)[source]

build_mdp builds the GROMACS mdp file required for an NPT equilibration

Parameters:

mdpname (str) – name of mdp file

default_params = {'P': 1, 'T': 300, 'gromacs': {'gmx': 'gmx', 'mdrun': 'gmx mdrun', 'mdrun_single_molecule': 'gmx mdrun mdrun', 'options': '-quiet -nobackup'}, 'input_gro': 'systems/final-results/final.gro', 'input_grx': 'systems/final-results/final.grx', 'input_top': 'systems/final-results/final.top', 'output_deffnm': 'equilibrate', 'ps': 1000, 'scatter': ('time(ps)', ['Density'], 'rho_v_ns.png'), 'subdir': 'postsim/equilibrate', 'traces': ['Temperature', 'Density', 'Volume']}
do(mdp_pfx='npt', **gromacs_dict)[source]

do handles executing the postsim MD simulation

Parameters:

mdp_pfx (str, optional) – filename prefix for output files, defaults to ‘npt’

class HTPolyNet.postsim.PostsimConfiguration[source]

Bases: object

handles reading and parsing a postcure simulation input config file. Config file format

  • { key1: {<paramdict>}}

  • { key2: {<paramdict>}}

The config file is a list of single-element dictionaries, whose single keyword indicates the type of MD simulation to be run; simulations are run in the order they appear in the config file.

Currently allowed simulation types:

  • ‘equilibrate’: simple NPT equilibration;

  • ‘anneal’: simple simulated annealing;

  • ‘ladder’: temperature ladder;

  • ‘deform: constant strain-rate uniaxial deformation;

default_classes = {'anneal': <class 'HTPolyNet.postsim.PostSimAnneal'>, 'deform': <class 'HTPolyNet.postsim.PostSimDeform'>, 'equilibrate': <class 'HTPolyNet.postsim.PostSimMD'>, 'ladder': <class 'HTPolyNet.postsim.PostSimLadder'>}
parse(**kwargs)[source]

parse parses a PostsimConfiguration file to build the list of stages to run

classmethod read(filename, parse=True, **kwargs)[source]

read generates a new PostsimConfiguration object by reading in the JSON or YAML file indicated by filename

Parameters:
  • filename (str) – name of file from which to read new PostsimConfiguration object

  • parse (bool, optional) – if True, parse the input configuration file, defaults to True

Raises:

Exception – if extension of filename is not ‘.json’ or ‘.yaml’ or ‘.yml’

Returns:

a new PostsimConfiguration object

Return type:

PostsimConfiguration

HTPolyNet.postsim.postsim(args)[source]

postsim handles the postsim subcommand for managing post-cure production MD simulations

Parameters:

args (argparse.Namespace) – command-line arguments

class HTPolyNet.projectfilesystem.ProjectFileSystem(root='.', topdirs=['molecules', 'systems', 'plots'], projdir='next', verbose=False, reProject=False, userlibrary=None, mock=False)[source]

Bases: object

Handles all aspects of the creation and organization of a project filesystem

cdproj()[source]

cdproj change the cwd to the toplevel project directory

cdroot()[source]

cdroot change the cwd to the root (parent directory of project directory)

go_to(subPath, make=False)[source]

go_to change the cwd to the directory named by ‘subPath’

Parameters:

subPath (str) – directory to change to, relative to project directory

class HTPolyNet.projectfilesystem.RuntimeLibrary[source]

Bases: object

a library object – default creation references the Library resource package.

checkin(filename, overwrite=False)[source]

checkin check filename into this RuntimeLibrary

Parameters:
  • filename (str) – name of file to check in, *relative to the top level directory in which the library is housed*

  • overwrite (bool, optional) – if True, overwrite the file in the RuntimeLibrary if it exists, defaults to False

Returns:

False if filename not found in cwd; True if check-in was successful

Return type:

bool

checkout(filename, searchpath=[], altpath=[])[source]

checkout check the file named by filename out of this RuntimeLibrary and copy it to the cwd

Parameters:
  • filename (str) – name of file to checkout, relative to the top level directory in which the library is found

  • searchpath (list, optional) – path of directories to search if the filename is not resolved, defaults to []

  • altpath (list, optional) – additional directories to add to the search path, defaults to []

Returns:

True if file checkout was successful, False if not

Return type:

bool

exists(filename)[source]

exists checks to see if filename exists in this RuntimeLibrary

Parameters:

filename (str) – name of file to check for, relative to toplevel directory of RuntimeLibrary

Returns:

True if filename exists in RuntimeLibrary, False otherwise

Return type:

bool

get_example_depot_location()[source]

get_example_depot_location reports the location of the examples in this RuntimeLibrary, if they exist

Returns:

name of depot directory

Return type:

str

get_example_names()[source]

get_example_names returns the names of the example tarballs

Returns:

list of names of example tarballs

Return type:

list

info()[source]

info returns a simple string describing this RuntimeLibrary

Returns:

the string

Return type:

str

classmethod system()[source]

system generates a RuntimeLibrary object corresponding to the installed Library subpackage

Parameters:

libpackage (str, optional) – name of the HTPolyNet Library subpackage, defaults to ‘Library’

Raises:

ImportError – if the system library subpackage is not found

Returns:

a RuntimeLibrary object holding the system library subpackage

Return type:

RuntimeLibrary

classmethod user(pathname='.')[source]

user generates a new user-level RuntimeLibrary object

Parameters:

pathname (str, optional) – where to find the library, defaults to ‘.’

Returns:

a new RuntimeLibrary object

Return type:

RuntimeLibrary

HTPolyNet.projectfilesystem.checkin(filename, overwrite=False, priority='user')[source]

checkin check the file named ‘filename’ into either the user-level local library or the global system Library package (the latter requires write priveleges wherever Python packages are stored if HTPolyNet is installed without -e or from PyPI)

Parameters:
  • filename (str) – name of file to check in

  • overwrite (bool, optional) – flag indicates whether file should overwrite file of same name in library, defaults to False

  • priority (str, optional) – string indicating which library to check into, defaults to ‘user’

HTPolyNet.projectfilesystem.checkout(filename, altpath=[])[source]

checkout handles checking files out of the library owned by the global ProjectFileSystem object; tries to checkout from user-level local library first before trying to check out from the global system Library subpackage

Parameters:
  • filename (str) – name of file to check out relative to top-level of library

  • altpath (list, optional) – list of alternate directories to search, defaults to []

Returns:

True if checkout from user library successful, otherwise returns result of checkout from global system Library (also a bool)

Return type:

bool

HTPolyNet.projectfilesystem.cwd()[source]

cwd returns name of current working directory relative to the root path

Returns:

name of current working directory relative to the root path

Return type:

os.path

HTPolyNet.projectfilesystem.exists(filename)[source]

exists checks for existence of filename in user-level local library, then in the system Library

Parameters:

filename (str) – name of file

Returns:

True if found in either library

Return type:

bool

HTPolyNet.projectfilesystem.fetch_molecule_files(mname)[source]

fetch_molecule_files fetches all relevant molecule data files for molecule named ‘mname’

Parameters:

mname (str) – name of molecule

Returns:

list of filetypes found and fetched

Return type:

list

HTPolyNet.projectfilesystem.go_proj()[source]

go_proj change the current working directory to the project directory

HTPolyNet.projectfilesystem.go_root()[source]

go_root change the current working directory to the root directory

HTPolyNet.projectfilesystem.go_to(pathstr)[source]

go_to Change the current working directory to “pathstr” which is relative to the project root.

Parameters:

pathstr (str) – pathname of directory relative to project root

Returns:

absolute path of current working direcory

Return type:

os.path

HTPolyNet.projectfilesystem.info()[source]

info prints some summary information about Libraries to the console

HTPolyNet.projectfilesystem.lib_setup()[source]

lib_setup sets up the system RuntimeLibrary

Returns:

system RuntimeLibrary object

Return type:

RuntimeLibrary

HTPolyNet.projectfilesystem.local_data_searchpath()[source]

local_data_searchpath returns container containing root path and project path

Returns:

list containing root path and project path

Return type:

list

HTPolyNet.projectfilesystem.pfs_setup(root='.', topdirs=['molecules', 'systems', 'plots'], projdir='next', verbose=False, reProject=False, userlibrary=None, mock=False)[source]

pfs_setup sets up the global ProjectFileSystem object

Parameters:
  • root (str, optional) – parent directory of this project file system, defaults to ‘.’

  • topdirs (list, optional) – top-level subdirectories, defaults to [‘molecules’,’systems’,’plots’]

  • projdir (str, optional) – name of the project directory itself, defaults to ‘next’

  • verbose (bool, optional) – flag indicating verbose output, defaults to False

  • reProject (bool, optional) – flag indicating restart, defaults to False

  • userlibrary (str, optional) – name of user library relative to root, defaults to None

  • mock (bool, optional) – flag indicating this is a mock call, defaults to False

HTPolyNet.projectfilesystem.proj()[source]

proj returns name of project directory

Returns:

name of project directory

Return type:

os.path

HTPolyNet.projectfilesystem.proj_abspath(filename)[source]

proj_abspath returns the path of the file named filename relative to the project directory

Parameters:

filename (str) – name of the probe file

Returns:

name of probe file relative to the project directory

Return type:

os.path

HTPolyNet.projectfilesystem.root()[source]

root returns name of root directory (parent of project directory)

Returns:

name of root directory

Return type:

os.path

HTPolyNet.projectfilesystem.subpath(name)[source]

subpath returns the path of the project subdirectory with name ‘name’

Parameters:

name (str) – name of subdirectory

Returns:

path of subdirectory

Return type:

os.path

HTPolyNet.projectfilesystem.system()[source]

system returns the system RuntimeLibrary object

Returns:

system RuntimeLibrary object

Return type:

RuntimeLibrary

class HTPolyNet.reaction.Reaction(jsondict={})[source]

Bases: object

default_directives = {'atoms': {}, 'bonds': [], 'name': '', 'probability': 1.0, 'procession': {}, 'product': '', 'reactants': {}, 'stage': reaction_stage.unset}
HTPolyNet.reaction.extract_molecule_reactions(rlist: list[Reaction], plot=True)[source]

extract_molecule_reactions establishes the correct order of reactions so that molecular templates are created in a sensible order (reactants before products for all reactions)

Parameters:
  • rlist (ReactionList) – list of all reactions

  • plot (bool, optional) – flag to plot the reaction network, defaults to True

Returns:

ordered list of tuples, reach of the from (name-of-product-molecule,Reaction)

Return type:

list of tuples

HTPolyNet.reaction.generate_product_name(R: Reaction)[source]

generate_product_name automatically generate the name of the product based on the names of the reactants and the bonds in R

Parameters:

R (Reaction) – a Reaction

Returns:

suggested name of product

Return type:

str

HTPolyNet.reaction.get_r(mname, RL: list[Reaction])[source]

get_r returns the Reaction that generates molecule mname as a product, if it exists, otherwise None

Parameters:
  • mname (str) – name of molecule to search

  • RL (ReactionList) – list of all Reactions

Returns:

Reaction that generates mname, or None

Return type:

Reaction or NoneType

HTPolyNet.reaction.is_reactant(name: str, reaction_list: list[Reaction], stage=reaction_stage.cure)[source]

is_reactant tests to see if molecule ‘name’ appears as a reactant in any reaction in reaction_list

Parameters:
  • name (str) – name of molecule

  • reaction_list (ReactionList) – list of all Reactions

  • stage (reaction_stage(Enum), optional) – stage or reactions to search, defaults to reaction_stage.cure

Returns:

True if molecule is a reactant, False otherwise

Return type:

bool

HTPolyNet.reaction.molname_sequence_resnames(molname: str, reactions: list[Reaction])[source]

molname_sequence_resnames determine monomer sequence of the molecule with name molname based on a traversal of the reaction network

Parameters:
  • molname (str) – name of molecule

  • reactions (ReactionList) – list of all Reactions

Returns:

monomer sequence of molecule as a list of monomer names

Return type:

list

HTPolyNet.reaction.parse_reaction_list(baselist: list[Reaction])[source]

parse_reaction_list generates any new reactions inferred by procession (i.e., linear polymerization)

Parameters:

baselist (ReactionList) – list of unprocessed reaction dicts read directly from configuration file

Returns:

entire set of all reactions, including new ones added here

Return type:

ReactionList

HTPolyNet.reaction.product_sequence_resnames(R: Reaction, reactions: list[Reaction])[source]

product_sequence_resnames recursively generate sequence of product of R by traversing network of reactions; sequence is by definition an ordered list of monomer names

Parameters:
  • R (Reaction) – a Reaction

  • reactions (ReactionList) – list of all Reactions

Returns:

the sequence of R’s product molecule as a list of monomer names

Return type:

list

HTPolyNet.reaction.reactant_resid_to_presid(R: Reaction, reactantName: str, resid: int, reactions: list[Reaction])[source]

reactant_resid_to_presid map the resid of a reactant monomer to its inferred resid in the associate product in reaction R, by traversing the reaction network

Parameters:
  • R (Reaction) – a Reaction

  • reactantName (str) – the name of one of the reactants in R

  • resid (int) – the resid in that reactant we want mapped to the product

  • reactions (ReactionList) – list of all Reactions

Returns:

resid of this residue in the product of R

Return type:

int

class HTPolyNet.reaction.reaction_stage(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumerated reaction stage

build = 0
cap = 3
cure = 2
param = 1
unset = 99
class HTPolyNet.ring.Ring(idx)[source]

Bases: object

copy()[source]
injest_coordinates(A, idx_key='globalIdx', pos_key=['posX', 'posY', 'posZ'])[source]
pierced_by(P)[source]

determines if segment with endpoints P[0] and P[1] pierces ring; uses ray projection method and fact that scaled length must be between 0 and 1 for a plane intersection

Parameters:

P – a 2-element numpy array of 3-space points

Returns:

True if P[0]-P[1] pierces self’s ring, along with the intersection point

Return type:

tuple (boolean, numpy.ndarray(3))

remap(mapper)[source]
shift(shift)[source]
treadmill()[source]

yield the treadmilled versions of the list

unwrap(P, unwrapf=None, pbc=[1, 1, 1])[source]
class HTPolyNet.ring.RingList(input_obj)[source]

Bases: UserList

all_atoms()[source]
filter(idxlist)[source]
injest_coordinates(A, idx_key='globalIdx', pos_key=['posX', 'posY', 'posZ'])[source]
remap(mapper)[source]
shift(shift)[source]
class HTPolyNet.ring.Segment(P)[source]

Bases: object

a segment object owns a list of Points P with two elements representing segment endpoints, and a vector that points from the first point to the second, V

HTPolyNet.ring.lawofcos(a, b)[source]

lawofcos return the cosine of the angle defined by vectors a and b if they share a vertex (the LAW OF COSINES)

Parameters:
  • a (numpy.ndarray(3,float)) – a vector

  • b (numpy.ndarray(3,float)) – another vector

Returns:

cosine of the angle formed by a and b

Return type:

float

class HTPolyNet.runtime.Runtime(cfgfile='', restart=False)[source]

Bases: object

Runtime class manages all aspects of a system build using HTPolyNet.

cfg

Fill in any default values

default_edict = {'ensemble': 'npt', 'nsteps': -2, 'pressure': 10, 'ps': 200, 'repeat': 0, 'temperature': 300}
do_cure()[source]

do_cure manages CURE algorithm execution.

Returns:

only returns None if CURE cannot execute

Return type:

None

do_densification(deffnm='densified')[source]
do_densification manages execution of gmx mdrun to perform minimization

and NPT MD simulation of the initial liquid system. Final coordinates are loaded into the global TopoCoord.

Parameters:
  • inpfnm (str, optional) – input file name prefix, defaults to ‘init’

  • deffnm (str, optional) – deffnm prefix fed to gmx mdrun, defaults to ‘npt-1’

Returns:

dictionary of Gromacs file names

Return type:

dict

do_initialization(inpfnm='init')[source]

do_initialization manages creation of the global system topology file and the execution of ‘gmx insert-molecules’ to create the initial simulation box

Parameters:

inpfnm (str, optional) – basename for output files, defaults to ‘init’

Returns:

dictionary of Gromacs files

Return type:

dict

do_postcure()[source]

do_postcure manages execution of mdrun to perform any post-cure MD simulation(s).

Returns:

dictionary of Gromacs file names

Return type:

dict

do_precure()[source]

do_precure manages execution of mdrun to perform any pre-cure MD simulation(s).

Returns:

dictionary of Gromacs file names

Return type:

dict

do_workflow(**kwargs)[source]

do_workflow manages runtime for one entire system-build workflow

generate_molecules(force_parameterization=False, force_checkin=False)[source]

generate_molecules manages creation and parameterization of all monomers and oligomer templates

Parameters:
  • force_parameterization (bool, optional) – forces AmberTools to run parameterizations, defaults to False

  • force_checkin (bool, optional) – forces HTPolyNet to overwrite molecule library, defaults to False

runtime_defaults = {'CURE': {}, 'ambertools': {'charge_method': 'gas'}, 'densification': {'aspect_ratio': array([1., 1., 1.]), 'equilibration': [{'ensemble': 'min'}, {'ensemble': 'nvt', 'ps': 10, 'temperature': 300}, {'ensemble': 'npt', 'pressure': 10, 'ps': 200, 'temperature': 300}], 'initial_density': 200.0}, 'gromacs': {'gmx': 'gmx', 'gmx_options': '-quiet -nobackup', 'mdrun': 'gmx mdrun'}, 'postcure': {'anneal': {'cycle_segments': [{'T': 300, 'ps': 0}, {'T': 600, 'ps': 20}, {'T': 600, 'ps': 20}, {'T': 300, 'ps': 20}, {'T': 300, 'ps': 20}], 'initial_temperature': 300, 'ncycles': 0}, 'postequilibration': {'ensemble': 'npt', 'pressure': 1, 'ps': 0, 'temperature': 300}}, 'precure': {'anneal': {'cycle_segments': [{'T': 300, 'ps': 0}, {'T': 600, 'ps': 20}, {'T': 600, 'ps': 20}, {'T': 300, 'ps': 20}, {'T': 300, 'ps': 20}], 'initial_temperature': 300, 'ncycles': 0}, 'postequilibration': {'ensemble': 'npt', 'pressure': 1, 'ps': 0, 'temperature': 300}, 'preequilibration': {'ensemble': 'npt', 'pressure': 1, 'ps': 100, 'temperature': 300}}}
save_data(result_name='final')[source]

save_data writes ‘gro’, ‘top’, ‘tpx’, and ‘grx’ files for system

Parameters:

result_name (str, optional) – output file basename, defaults to ‘final’

Returns:

dictionary of Gromacs file basenames

Return type:

dict

HTPolyNet.runtime.logrotate(filename)[source]

logrotate renames any existing log file with name ‘filename’ using a pattern that prevents overwriting any old logs

Parameters:

filename (str) – name of log file

class HTPolyNet.software.Software[source]

Bases: object

ambertools = ['antechamber', 'tleap', 'parmchk2']
getVersions()[source]

getVersions attempts to determine versions of AmberTools

info()[source]
set_gmx_preferences(parameters)[source]

set_gmx_preferences set the necessary resolution of gromacs executables based on directives in the parameters parameter

Parameters:

parameters (dict) – dictionary read in from cfg file

HTPolyNet.software.info()[source]
HTPolyNet.software.set_gmx_preferences(parmdict)[source]

set_gmx_preferences sets the global Gromacs preferences

Parameters:

parmdict (dict) – dictionary from cfg file

HTPolyNet.software.sw_setup()[source]

sw_setup sets up the global Software object

HTPolyNet.software.to_string()[source]
HTPolyNet.stringthings.my_logger(msg, logf, width=67, fill='*', sep=', ', just='^')[source]
class HTPolyNet.topocoord.BTRC(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Bond test return codes: bond tests are applied to those bond-candidates that are within search radius of each other

Parameters:

Enum (class) – inherits from Enum class

failed_pierced_ring = 1
failed_shortcircuit = 2
passed = 0
unset = 99
class HTPolyNet.topocoord.TopoCoord(topfilename='', tpxfilename='', grofilename='', grxfilename='', mol2filename='', system_name='htpolynet', **kwargs)[source]

Bases: object

Container for Topology and Coordinates, along with methods that use either or both of them

add_length_attribute(bdf: DataFrame, attr_name='length')[source]

add_length_attribute computes bond lengths based on bonds indicated by the parallel ‘ai’ and ‘aj’ columns of the parameter dataframe bdf and stores result in a new column called attr_name

Parameters:
  • bdf (pd.DataFrame) – a pandas dataframe with ‘ai’ and ‘aj’ columns of atom indices indicating bonds

  • attr_name (str, optional) – name of length attribute column, defaults to ‘length’

add_restraints(pairdf, typ=6)[source]

Adds bonds of type typ to the topology from the dataframe pairdf

Parameters:
  • pairdf (pandas.DataFrame) – ai, aj, initital-distance

  • typ (int, optional) – bond type to add, defaults to 6 (non-topological restraint)

adjust_charges(atoms=[], overcharge_threshhold=0.1, netcharge=0.0, msg='')[source]

adjust_charges adjust the partial charges on atoms in list ‘atoms’ if the absolute net charge exceeds ‘netcharge’ by the ‘overcharge_threshhold’

Parameters:
  • atoms (list, optional) – list of atom indexes to consider, defaults to []

  • overcharge_threshhold (float, optional) – absolute deviation from netcharge that triggers adjustment, defaults to 0.1

  • netcharge (float, optional) – desired net charge, defaults to 0.0

  • msg (str, optional) – a little message to echo to console if adjustment is necessary, defaults to ‘’

are_bonded(i, j)[source]

are_bonded checks to see if atoms with indices i and j are bonded to each other

Parameters:
  • i (int) – an atom global index

  • j (int) – another atom global index

Returns:

True if atoms are bonded, False otherwise

Return type:

bool

atom_count()[source]
atom_count Check to be sure the Coordinate and Topology members contain the same number of

atoms

Returns:

the number of atoms

Return type:

int

attenuate_bond_parameters(bonds, i, n, minimum_distance=0.0, init_colname='initial_distance')[source]
Alter the kb and b0 parameters for new crosslink bonds according to the values prior to

relaxation (stored in lengths), their equilibrium values, and the ratio stage/max_stages. Let stage/max_stages be x, and 1/max_stages <= x <= 1. The spring constant for each bond is multiplied by x and the distance is 1 xth of the way from its maximum value to its equilibrium value.

Parameters:
  • bonds (pandas.DataFrame) – bonds dataframe, ‘ai’, ‘aj’, ‘initial_distance’

  • stage (int) – index of stage in the series of post-bond-formation relaxation

  • max_stages (int) – total number of relaxation stages for this iteration

  • minimum_distance – minimum bondlegth allowed, overriding type-specific b0

attenuate_pair_parameters(pairdf, i, n, draglimit_nm=0.3)[source]
Alter the kb and b0 parameters for new pre-crosslink pairs according

to the values prior to dragging (stored in pairdf[‘initial_distances’]), the desired lower limit of interatomic distance ‘draglimit_nm’, and the ratio stage/max_stages.

Parameters:
  • pairdf (pandas.DataFrame) – pairs dataframe ([‘ai’],[‘aj’],[‘initial_distance’])

  • stage (int) – index of stage in the series of pre-bond-formation dragging

  • max_stages (int) – total number of drag stages for this iteration

  • draglimit_nm (float) – lower limit of interatomic distance requested from drag

bondcycle_collective(bdf: DataFrame)[source]

bondcycle_collective Check to see if, when considered as a collective, this set of bondrecs leads to one or more cyclic bondchains; if so, longest bonds that break bondcycles are removed from bondrecs list and resulting list is returned

Parameters:

bdf (pandas.DataFrame) – bonds data frame, sorted in ascending order by bondlength

Returns:

list of bond records that results in no new bondcycles

Return type:

list

bondtest(b, pbc=[1, 1, 1], show_piercings=True)[source]
Determine if bond b is to be allowed to form based on geometric and

topological criteria

Parameters:
  • b (2-tuple) – bond, tuple (ai,aj,rij)

  • pbc (list, optional) – periodic boundary condition flags in each direction, defaults to [1,1,1]

  • show_piercings (bool) – flag indicating you want to write gro files showing pierced rings

Returns:

BTRC instance

Return type:

BTRC enum

bondtest_df(df: DataFrame, pbc=[1, 1, 1], show_piercings=True)[source]

bondtest_df applies bond filters to all bonds in the dataframe;

Parameters:
  • df (pd.DataFrame) – dataframe of possible bonds; dataframe should have columns ‘ai’, ‘aj’ and ‘r’; this method adds the column ‘results’

  • pbc (list, optional) – flags indicating dimensions in which pbc are used, defaults to [1,1,1]

  • show_piercings (bool, optional) – toggles diagnostic output for pierced rings, defaults to True

Returns:

input data frame with new ‘results’ column

Return type:

pandas.DataFrame

center_coords(new_boxsize: ndarray = None)[source]

center_coords center all coordinates in box

Parameters:

new_boxsize (numpy.ndarray, optional) – new boxsize if desired, defaults to None

check_your_topology()[source]

check_your_topology checks topology for duplicate 1-4 pair interactions and deletes them

checkbox()[source]

checkbox checks that the entire constellation of points in the atoms dataframe fits within the designated box for this Configuration object

Returns:

True,True if both lower-leftmost and upper-rightmost points are within the box

Return type:

tuple(bool,bool)

copy_bond_parameters(bonds)[source]
Generate and return a copy of a bonds dataframe that contains all bonds

listed in bonds

Parameters:

bonds (list) – list of bonds, each a 2-tuple of global atom indices

Returns:

bonds dataframe

Return type:

pandas.DataFrame

copy_coords(other)[source]

Copy coordinates and box size from other to self

Parameters:

other (TopoCoord) – a TopoCoord instance

count_H(idx)[source]

count_H Counts the number of hydrogens bound to atom with index idx; any atom whose name begins with the character ‘H’ or ‘h’ is assumed to be a hydrogen!

Parameters:

idx (int) – atom global index

Returns:

number of H atoms bound to this atom

Return type:

int

decrement_gro_attribute_by_attributes(att_name, attribute_dict)[source]

decrement_gro_attribute_by_attributes subtract one from attribute att_name of all atoms identified by attribute:value pairs in attribute_dict

Parameters:
  • att_name (str) – name of attribute to increment

  • attribute_dict (dict) – attribute:value pairs that specify atoms to which to apply this incrementation

delete_atoms(atomlist)[source]

Deletes atoms from both the Topology and Coordinates instances

Parameters:

atomlist (list) – list of global indexes of atoms to delete

Returns:

old-to-new atom global index mapper dictionary resulting from reindexing remaining atoms to make sure global indexes are sequential

Return type:

dict

density(units='SI')[source]

density returns system density

Parameters:

units (str, optional) – unit designation, defaults to ‘SI’

Returns:

density

Return type:

float

enumerate_1_4_pairs(at_idx)[source]

enumerate_1_4_pairs enumerate all 1-4 pair interactions resulting from new bonds in at_idx

Parameters:

at_idx (list) – list of 2-tuples, each containing global indices of atoms that bond to each other

Returns:

dataframe of all pairs

Return type:

pandas.DataFrame

equilibrate(deffnm='equilibrate', edict={}, gromacs_dict={})[source]

equilibrate perform an MD simulation using mdrun

Parameters:
  • deffnm (str, optional) – output file basename, defaults to ‘equilibrate’

  • edict (dict, optional) – dictionary of simulation directives, defaults to {}

  • gromacs_dict (dict, optional) – dictionary of gromacs directives, defaults to {}

Returns:

list of edr files this equilibration generates

Return type:

list

flip_stereocenters(idxlist)[source]

flip_stereocenters flips stereochemistry of atoms in idxlist

Parameters:

idxlist (list) – global indices of chiral atoms

classmethod from_top_gro(top, gro)[source]
get_R(idx)[source]

get_R return the cartesian position of atom with global index idx

Parameters:

idx (int) – atom global index

Returns:

position of atom

Return type:

numpy.ndarray(3,float)

get_bystanders(atom_idx)[source]

get_bystanders identify and return bystanders at a particular proposed bond specified by atom_idx

Parameters:

atom_idx (container) – container of two global atom indices specifying a proposed bond

Returns:

4-tuple of special bystander info containers

Return type:

tuple

get_gro_attribute_by_attributes(att_name, attribute_dict)[source]

get_gro_attribute_by_attributes return values of attributes listed in name from atoms specified by attribute:value pairs in attribute_dict

Parameters:
  • att_name (list) – list of attributes whose values are to be returned

  • attribute_dict (dict) – dictionary of attribute:value pairs that specify the set of atoms to be considered

Returns:

scalar or list of one or more return attribute values

Return type:

list if name is a list; scalar otherwise

get_gro_attributelist_by_attributes(attribute_list, attribute_dict)[source]

get_atoms_w_attribute returns all rows of atoms dataframe and columns named in names of atoms identified by the attributes dict

Parameters:
  • attribute_list – list of attributes to be in the rows that are returned

  • attribute_dict (dict) – dictionary of attribute:value pairs that specify the set of atoms to be considered

Returns:

a dataframe segment

Return type:

pd.DataFrame

get_oneaways(atom_idx)[source]

get_oneaways identify and return one-aways for a particular proposed bond specified by atom_idx

Parameters:

atom_idx (list) – two-element container of atom indices specifying proposed bond

Returns:

tuple of oneaways-lists

Return type:

tuple

get_resid_sets(atom_pair)[source]

get_resid_sets identifies individual sets of separate resids owned by unbonded atoms i and j

Parameters:

atom_pair (tuple) – tuple of i,j atom indices

Returns:

tuple containing the two apposing residue sets

Return type:

tuple

grab_files()[source]

grab_files using absolute pathname information, grab the most up-to-date gromacs files for this system and deposit them into the cwd

gro_DataFrame(name)[source]

gro_DataFrame return the appropriate Coordinates dataframe based on the directive in ‘name’

Parameters:

name (str) – either ‘atoms’ or ‘mol2_bonds’

Returns:

the desired dataframe

Return type:

pandas.DataFrame

grompp_and_mdrun(out, mdp, mylogger=<bound method Logger.debug of <Logger HTPolyNet.topocoord (WARNING)>>, **kwargs)[source]

grompp_and_mdrun manages invoking a single Gromacs run using the current TopoCoord

Parameters:
  • out (str) – output filename basename

  • mdp (str) – name of mdp file

  • mylogger (logging.logger, optional) – a logger, defaults to logger.debug

Returns:

any message generated by gromacs.grompp_and_mdrun

Return type:

str

increment_gro_attribute_by_attributes(att_name, attribute_dict)[source]

increment_gro_attribute_by_attributes add one to attribute att_name of all atoms identified by attribute:value pairs in attribute_dict

Parameters:
  • att_name (str) – name of attribute to increment

  • attribute_dict (dict) – attribute:value pairs that specify atoms to which to apply this incrementation

inherit_grx_attributes_from_molecules(molecule_dict, initial_composition, globally_unique=[False, False, False, True, True, False, True, False], unset_defaults=[0, 0, 'UNSET', -1, -1, -1, -1, 'UNSET'], overall_default=0)[source]

inherit_grx_attributes_from_molecules Copy non-Gromacs-standard atom attributes in list “attributes” from molecule templates in molecule_dict according to molecule counts in dict initial_composition.

Parameters:
  • attributes (list) – list of labels of attributes to copy

  • molecule_dict (dict) – dictionary of available molecules (name:Molecule)

  • initial_composition (dict) – dictionary of initial composition (name:count)

  • globally_unique (list, optional) – boolean list indicating attributes that must be globally unique, defaults to []

  • unset_defaults (list, optional) – list of values, one per attribute, that signify UNSET, defaults to []

  • overall_default (int, optional) – default UNSET value for all attributes if unset_defaults is empty, defaults to 0

interresidue_partners_of(i)[source]

interresidue_partners_of return list of atom indices that are bonded partners of atom i and are not in the residue of atom i

Parameters:

i (int) – atom global index

Returns:

list of atom indices of atoms that are partners of i not in i’s residue

Return type:

list

linkcell_cleanup()[source]

linkcell_cleanup removes linkcell_idx attribute from Coordinate.A

linkcell_initialize(cutoff, ncpu=1, force_repopulate=True)[source]

linkcell_initialize Initialize the linkcell structure; a wrapper for Coordinates

Parameters:
  • cutoff (float) – minimum value of cell side-length

  • ncpu (int) – number of processors to use in populating linkcell structure in parallel, default 1

load_files(filenames: dict)[source]

load_files load all gromacs files into TopoCoord

Parameters:

filenames (dict) – dictionary of extension:filename

make_bonds(pairs, explicit_sacH={})[source]

Adds new bonds to the global topology

Parameters:
  • pairs (list) – list of pairs of atom global indices indicating each new bond

  • skip_H (list, optional) – list of pairs of atom global indices to skip when identifying the sacrificial H atoms; likely these are identified during molecule-building to optimize mutual orientation and placement of the two reactant molecules, defaults to []

Returns:

list of indexes of atoms that must now be deleted (sacrifical H’s)

Return type:

list

make_resid_graph(json_file=None)[source]

make_resid_graph make a residue connectivity graph

Parameters:

json_file (str, optional) – name of output JSON file to write, defaults to None

makes_shortcircuit(i, j)[source]
Determine whether atoms i and j, if bonded, would produce a short circuit,

defined as an instance in which i and j belong to residues that are already bonded to each other

Parameters:
  • i (int) – global index of first atom

  • j (int) – global index of second atom

Returns:

True if a short circuit would happen, False otherwise

Return type:

bool

map_from_templates(bdf, moldict, overcharge_threshhold=0.1)[source]
Updates angles, pairs, dihedrals, atom types, and charges, based on product

templates associated with each bond in ‘bdf’

Parameters:
  • bdf (pandas.DataFrame) – dataframe, columns ‘ai’, ‘aj’, ‘reactantName’

  • moldict (dict) – dictionary of template Molecules keyed by name

Raises:
  • Exception – nan found in any attribute of any new system angle

  • Exception – nan found in any attribute of any new system dihedral

  • Exception – nan found in any attribute of any new system pair that came along with a dihedral

  • Exception – nan found in ai attribute of any template pair

  • Exception – nan found in aj attribute of any template pair

  • Exception – nan found in any system pair

maxspan()[source]
maxspan Returns the maxspan of the Coordinates (dimensions of orthorhombic

convex hull enclosing Coordinates). Just a wrapper.

Returns:

array of x-span, y-span, z-span

Return type:

numpy.ndarray

merge(other)[source]

merge Merges the TopoCoord instance “other” to self

Parameters:

other (TopoCoord) – another TopoCoord instance

Returns:

a shift tuple (returned by Coordinates.merge())

Return type:

tuple

minimum_distance(other, self_excludes=[], other_excludes=[])[source]

minimum_distance computes the distance of closest approach between self’s Coordinates that other’s Coordinates

Parameters:
  • other (TopoCoord) – another TopoCoord object

  • self_excludes (list, optional) – list of global atom indices to ignore in self, defaults to []

  • other_excludes (list, optional) – list of global atom indices to ignore in other, defaults to []

Returns:

distance of closest approach: i.e., the distance between the two atoms, one from self and one from other, that are closest together

Return type:

float

minmax()[source]

minmax returns the coordinates of the atoms at the lower-leftmost and upper-rightmost positions in the constellation of points in the atoms dataframe

Returns:

tuple of two points, lower-leftmost and upper-rightmost, respectively

Return type:

tuple(np.ndarray(3,float),np.ndarray(3,float))

overwrite_coords(other)[source]

overwrite_coords overwrite coordinates in self by those in other

Parameters:

other (TopoCoord) – another TopoCoord object

partners_of(i)[source]

partners_of return list of atom indices of bonded partners of atom i

Parameters:

i (int) – global index of atom

Returns:

list of partner global indices

Return type:

list

pierces_ring(i, j, pbc=[1, 1, 1], show_piercings=True)[source]

pierces_ring checks to see if bond i-j would pierce any covalent ring structure

Parameters:
  • i (int) – global index of an atom

  • j (int) – global index of another

  • pbc (list, optional) – flags indicating which dimensions have pbc applied, defaults to [1,1,1]

  • show_piercings (bool, optional) – toggles diagnostic output of ring piercings, defaults to True

Returns:

True if a ring is pierced; False otherwise

Return type:

bool

read_gro(grofilename, preserve_box=False, wrap_coords=False)[source]
read_gro Creates a new Coordinates member by reading from a Gromacs-style coordinates

file. Just a wrapper for the read_gro method of Coordinates

Parameters:

grofilename (str) – name of gro file

read_gro_attributes(grxfilename, attribute_list=[])[source]

Read attributes from file into self.Coordinates.A

Parameters:
  • grxfilename (str) – name of input file

  • attribute_list (list, optional) – list of attributes to take, defaults to [] (take all)

read_mol2(mol2filename, **kwargs)[source]
read_mol2 Creates a new Coordinates member by reading from a SYBYL-style MOL2 file.

A wrapper for read_mol2 from Coordinates, but also sets the ‘mol2_bonds’ dataframe in the Topology if the parameter ignore_bonds is False. If the mol2_bonds dataframe is created, and the Topology already has a ‘bonds’ dataframe, a consistency check is peformed.

Parameters:

mol2filename (str) – name of mol2 file

read_top(topfilename)[source]
read_top Creates a new Topology member by reading from a Gromacs-style top file.

Just a wrapper for the read_top method of the Topology class

Parameters:

topfilename (str) – name of topology file

read_top_gro(topfilename, grofilename)[source]

read_top_gro Wrapper for read_top and read_gro; generates new Topology and Coordinates members

Parameters:
  • topfilename (str) – name of topology file

  • grofilename (str) – name of coordinates file (Gromacs format)

read_tpx(tpxfilename)[source]

reads in extended topology information

Parameters:

tpxfilename (str) – name of tpx file

remove_restraints(pairsdf)[source]

Remove all bonds represented in in pairdf. These are interpreted as non-topological restraints, so deleting these ‘bonds’ does not influence angles or dihedrals

Parameters:

pairdf (pandas DataFrame) – dataframe of pairs [‘ai’,’aj’]

reset_grx_attributes_from_idx_list(list_name)[source]

reset_grx_attributes_from_idx_list uses information in the “index lists” to repopulate appropriate GRX attributes. Currently, there is only one index list, for bondchains. Each index list is a list of lists; each element corresponds to a unique structure (bondchain) and is a list of global atom indices for atoms that make up that structural instance.

Parameters:

list_name (str) – only allowed value currently is ‘bondchain’

reset_idx_list_from_grx_attributes(list_name)[source]

reset_idx_list_from_grx_attributes is the inverse of reset_grx_attributes_from_idx_list: it uses the GRX attributes to rebuild index lists.

Parameters:

list_name (str) – either only allowed value currently is ‘bondchain’

resid_partners_of(ri)[source]

resid_partners_of return list of resid partners of resid ri

Parameters:

ri (int) – residue index

Returns:

list of partner residue indices (two residues are partners if there is at least one interatomic bond joining them)

Return type:

list

restore_bond_parameters(saved)[source]

Retores saved bond parameters in df saved by overwriting

Parameters:

saved (pandas.DataFrame) – [ bonds ] dataframe

return_bond_lengths(bdf)[source]

return_bond_lengths Return the length of all bonds in list bonds

Parameters:

bdf – bonds dataframe, ‘ai’,’aj’,’reactantName’

Returns:

list of lengths parallel to bonds

Return type:

list of floats

rotate(R)[source]

rotate applies rotation matrix R to all atom positions

Parameters:

R (numpy.ndarray((3,3),float)) – rotation matrix

set_gro_attribute(attribute, srs)[source]

set_gro_attribute sets attribute of atoms to srs (drills through to Coordinates.set_atomset_attributes())

Parameters:
  • attribute (str) – name of attribute

  • srs (scalar or list-like) – scalar or list-like attribute values in same ordering as self.A

set_gro_attribute_by_attributes(att_name, att_value, attribute_dict)[source]

set_atom_attribute set the attributes named in name to values named in values (names||values) for the set of atoms specified in the attributes dict

Parameters:
  • name (list) – list of names of attributes

  • value (list) – list of values of attributes to be set

  • attributes (dict) – dictionary of attribute:value pairs that specify the set of atoms to be considered

set_grx_attributes(attributes=[])[source]

set_grx_attributes override the global GRX_ATTRIBUTES

Parameters:

attributes (list, optional) – new GRX attributes to use, defaults to []

swap_atom_names(ai, aj)[source]

swap_atom_names Swaps the names of the two atoms with global indicies ai and aj. This is used when automatically selected which of several possible sacrificial H’s will actually be selected. Surviving H’s are renamed so it always appears that the H with “least important” name (lowest order if sorted) is the sacrificial H. Why do we do this? It gives us perfect control of the names of the atoms that survive a bond.

Parameters:
  • ai (int) – global index of first atom

  • aj (int) – global index of second atom

total_mass(units='SI')[source]

total_mass Returns the total mass of the system. Just a wrapper.

Parameters:

units (str, optional) – units designation, defaults to ‘SI’ (other option is ‘gromacs’)

Returns:

mass

Return type:

float

total_volume(units='SI')[source]

total_volume returns total volume represented by the system’s Coordinates

Parameters:

units (str, optional) – unit designation, defaults to ‘SI’

Returns:

box volume

Return type:

float

translate(L)[source]

translate applies translation vector L to all atom positions

Parameters:

L (numpy.ndarray(3,float)) – translation vector

update_topology_and_coordinates(bdf, template_dict={}, write_mapper_to=None, **kwargs)[source]

update_topology_and_coordinates updates global topology and necessary atom attributes in the configuration to reflect formation of all bonds listed in keepbonds

Parameters:
  • bdf (pandas.DataFrame) – bonds dataframe, columns ‘ai’, ‘aj’, ‘reactantName’

  • template_dict (dict) – dictionary of molecule templates keyed on molecule name

Returns:

3-tuple: new topology file name, new coordinate file name, list of bonds with atom indices updated to reflect any atom deletions

Return type:

3-tuple

vacuum_minimize(outname='minimized', **kwargs)[source]

vacuum_minimize the minimize analog to grompp_and_mdrun; performs an energy minimization using mdrun

Parameters:

outname (str, optional) – output file basename, defaults to ‘minimized’

vacuum_simulate(outname='simulated', **kwargs)[source]

vacuum_simulate peform a vacuum MD simulation using mdrun

Parameters:

outname (str, optional) – output file basename, defaults to ‘simulated’

wrap_coords()[source]

wrap_coords wrap all coordinates into center periodic box

write_gro(grofilename, grotitle='')[source]

write_gro Write a Gromacs-format coordinate file; wrapper for Coordinates.write_gro()

Parameters:

grofilename (str) – name of file to write

write_gro_attributes(attributes_list, grxfilename)[source]

write_gro_attributes Writes atomic attributes to a file

Parameters:
  • attributes_list (list) – list of attributes to write

  • grxfilename (str) – name of output file

write_grx_attributes(grxfilename)[source]

write_grx_attributes Writes GRX attributes to a file

Parameters:

grxfilename (str) – name of output file

write_mol2(filename, molname='', element_names_as_types=False)[source]
write_mol2 Writes a SYBYL MOL2-format file using Coordinates, with certain

atom attributes borrowed from the Topology

Parameters:
  • filename (str) – name of file to write

  • molname (str, optional) – name of molecule to put in mol2 file, defaults to ‘’

write_top(topfilename)[source]
write_top Write a Gromacs-format topology file; this will only write an in-line version,

no itp; wrapper for Topology.write_top()

Parameters:

topfilename (str) – name of file to write

write_tpx(tpxfilename)[source]
HTPolyNet.topocoord.find_template(BT: BondTemplate, moldict)[source]

find_template searches the dictionary of available molecules to identify a bond template that matches the passed-in template, returning the corresponding template molecule and reaction-bond

Parameters:
  • BT (BondTemplate) – bond template to search for

  • moldict (MoleculeDict) – dictionary of available molecule

Raises:

Exception – if no matching template is found

Returns:

template Molecule object, corresponding ReactionBond object from that template, and a boolean flag indicating whether or not the match required a symmetric-reversal of the template

Return type:

tuple(Molecule,ReactionBond,bool)

class HTPolyNet.topology.Topology(system_name='')[source]

Bases: object

Class for handling gromacs top data

add_bonds(pairs=[])[source]

add_bonds Adds bonds indicated in list pairs to the topology

Parameters:

pairs (list, optional) – list of pairs of atom indexes, defaults to []

Raises:

Exception – dies if an existing bond is in the list of pairs

add_restraints(pairdf, typ=6, kb=300000.0)[source]

Add type-6 (non-topoogical) bonds to help drag atoms destined to be bonded closer together in a series of dragging simulations

Parameters:
  • pairdf (pandas DataFrame) – dataframe of pairs [‘ai’,’aj’]

  • typ (int, optional) – bond type, defaults to 6

  • kb (float, optional) – bond spring constant (kJ/mol/nm^2), defaults to 300000

adjust_charges(atoms=[], desired_charge=0.0, overcharge_threshhold=0.1, msg='')[source]

Adjust atom partial charges a tiny bit so that total system charge is zero

Parameters:
  • desired_charge (float, optional) – target system charge, defaults to 0.0

  • overcharge_threshhold (float, optional) – threshold overcharge that triggers a message, defaults to 0.1

  • msg (str, optional) – A message to write if pre-adjusted system charge is too high, defaults to ‘’

Returns:

self topology

Return type:

Topology

atomcount()[source]

atomcount Returns the total number of atoms

Returns:

number of atoms

Return type:

int

attenuate_bond_parameters(bondsdf, stage, max_stages, minimum_distance=0.0, init_colname='initial_distance')[source]
Alter the kb and b0 parameters for new crosslink bonds according to the values prior to

relaxation (stored in lengths), their equilibrium values, and the ratio stage/max_stages. Let stage/max_stages be x, and 1/max_stages <= x <= 1. The spring constant for each bond is multiplied by x and the distance is 1 xth of the way from its maximum value to its equilibrium value.

Parameters:
  • bonds (pandas.DataFrame) – dataframe of bonds managed by runtime, ‘ai’,’aj’,’reactantName’

  • stage (int) – index of stage in the series of post-bond-formation relaxation (“R” of SCUR)

  • max_stages (int) – total number of relaxation stages for this iteration

  • minimum_distance – minimum bondlegth allowed, overriding type-specific b0 (if greater than 0)

attenuate_pair_parameters(pairsdf, stage, max_stages, draglimit_nm=0.3)[source]
Alter the kb and b0 parameters for new pre-crosslink pairs according

to the values prior to dragging (stored in pairdf[‘initial_distances’]), the desired lower limit of interatomic distance ‘draglimit_nm’, and the ratio stage/max_stages.

Parameters:
  • pairdf (pandas.DataFrame) – pairs dataframe ([‘ai’],[‘aj’],[‘initial_distance’])

  • stage (int) – index of stage in the series of pre-bond-formation dragging

  • max_stages (int) – total number of drag stages for this iteration

  • draglimit_nm (float) – lower limit of interatomic distance requested from drag

bond_source_check()[source]

bond_source_check Checks to ensure the ‘bonds’ dataframe and ‘mol2_bonds’ dataframe contain the same bonds. A mol2 dataframe is only created when a mol2 file is read by the Coordinates module.

build_interresidue_graph(G, ri)[source]
copy_bond_parameters(bonds)[source]
Generate and return a copy of a bonds dataframe that contains all bonds

listed in bonds

Parameters:

bonds (pandas.DataFrame) – dataframe of bonds managed by runtime, ‘ai’,’aj’,’reactantName’

Returns:

[ bonds ] dataframe extracted from system with all parameters

Return type:

pandas.DataFrame

delete_atoms(idx=[], reindex=True, return_idx_of=[], **kwargs)[source]

Delete atoms from topology

Parameters:
  • idx (list, optional) – list of atom indexes to delete, defaults to []

  • reindex (bool, optional) – reindex atoms after deleting, defaults to True

  • return_idx_of (list, optional) – list of old indices to report new indices of, defaults to []

Returns:

old-index-to-new-index mapper

Return type:

dict

detect_rings()[source]

detect_rings detect unique rings in the topology

dup_check(die=True)[source]

Check for duplicate type-like topology records

Parameters:

die (bool, optional) – flag telling HTPolyNet to exit if duplicate found, defaults to True

Raises:

Exception – Exception raised if duplicate found and die is True

classmethod from_ex(other)[source]
from_ex make a new Topology instance by copying only the extensive dataframes

from an existing topology, plust the bondlist and ringlist

Parameters:

other (Topology) – the other topology

Returns:

a new Topology generated by the extensive dataframes of other

Return type:

Topology

get_atom_attribute(idx, attribute)[source]

Return value of attribute of atom idx

Parameters:
  • idx (int) – global atom index

  • attribute (str) – atom attribute name

Returns:

atom attribute value

Return type:

varies

get_atomtype(idx)[source]

Get atom type of atom with global index idx

Parameters:

idx (int) – atom global index

Returns:

atom typ

Return type:

str

get_bond_parameters(ai, aj)[source]

Gets b0 and kb for bond between atoms with global indexes ai and aj

Parameters:
  • ai (int) – global atom index

  • aj (int) – global atom index

Returns:

b0, kb – equilibrium bond length and spring constant

Return type:

2-tuple

local_resid_cluster(ri)[source]
make_resid_graph(json_file=None)[source]
merge(other)[source]

Merge topologies

Parameters:

other (Topology) – a topology

merge_ex(other)[source]
merge_types(other)[source]

Merge type-like topology dataframes from other to self

Parameters:

other (Topology) – topology containing attribute D, a dictionary of dataframes

null_check(msg='')[source]

Paranoid checking for NaNs in dataframe locations that SHOULD NEVER HAVE NANS

Parameters:

msg (str, optional) – a nice message, defaults to ‘’

Raises:

Exception – exits if a NaN is found

classmethod read_top(filename, pad=-99.99)[source]

read_top Reads a Gromacs-style topology file ‘filename’ and returns a dictionary keyed on directive names. Each value in the dictionary is a pandas dataframe. Each dataframe represents an individual section found with its directive in the file, with columns corresponding to the fields in the section. Note that the we allow for input topology/itp files to have two ‘dihedrals’ and ‘dihedraltypes’ sections; these are merged in the result.

Parameters:

filename (str) – name of gromacs top file to read

Raises:

KeyError – If an unrecognized topology directive is encountered, program exits on error

Returns:

a Topology instance

Return type:

Topology

read_tpx(filename)[source]
remove_restraints(pairdf)[source]

Remove all bonds represented in in pairdf. These are interpreted as non-topological restraints, so deleting these ‘bonds’ does not influence angles or dihedrals

Parameters:

pairdf (pandas DataFrame) – dataframe of pairs [‘ai’,’aj’]

rep_ex(count=0)[source]

Replicate extensive topology components (atoms, pairs, bonds, angles, dihedrals)

Parameters:

count (int, optional) – number of replicas to generate, defaults to 0

Raises:

Exception – Dies if self is missing an atoms dataframe

report_duplicate_types(other, typename='', funcidx=4)[source]
report_type(typidx_q, typename='', funcidx=-1)[source]
reset_override_from_type(interactionname, typename, inst_idx)[source]
reset_type(typename, typidx_t, values)[source]
restore_bond_parameters(df)[source]

Copy data from all bonds in dataframe df to global dataframe

Parameters:

df (pandas DataFrame) – dataframe of bonds [‘ai’,’aj’,’c0’,’c1’]

shiftatomsidx(idxshift, directive, rows=[], idxlabels=[])[source]

shiftatomsidx shifts all atoms indexes in topology directive dataframe

Parameters:
  • idxshift (int) – integer index shift

  • directive (string) – name of gromacs topology directive (‘atoms’,’bonds’,’pairs’,’angles’,’dihedrals’)

  • rows (list, optional) – row boundaries, defaults to []

  • idxlabels (list, optional) – names of columns that contain atom indexes, defaults to []

total_charge()[source]

Compute and return total system charge

Returns:

charge

Return type:

float

total_mass(units='gromacs')[source]

Returns total mass of all atoms in the Topology.

Parameters:

units (str, optional) – unit system designation; if ‘SI’ returns kg, defaults to ‘gromacs’

Returns:

mass (in amu if units is ‘gromacs’ or kg if units is ‘SI’)

Return type:

float

write_top(filename)[source]

Write topology to a gromacs-format top file

Parameters:

filename (str) – name of top file to write

write_tpx(filename)[source]
HTPolyNet.topology.df_typeorder(df, typs)[source]

df_typeorder type-orders the atom type attributes in each row of dataframe df

Parameters:
  • df (pandas.DataFrame) – a Topology type-directive dataframe; [ atomtypes ], [ bondtypes ], etc.

  • typs (list) – list of type-attribute names; typically [‘i’,’j’,…]

HTPolyNet.topology.idxorder(a)
typeorder correctly order the tuple of atom types for particular

interaction types to maintain sorted type dataframes

Parameters:

a (tuple) – tuple of atom indicies/types from a [ bond ], [ pair ], [ angle ], or [ dihedral ] record

Returns:

same atom indices/types correctly ordered to allow for easy searching/sorting

Return type:

tuple

HTPolyNet.topology.repeat_check(t, msg='')[source]

repeat_check Check for repeated index tuples

Parameters:
  • t (list) – list of index tuples

  • msg (str, optional) – optional message, defaults to ‘’

HTPolyNet.topology.select_topology_type_option(options, typename='dihedraltypes', rule='stiffest')[source]

select_topology_type_option select from a list of topological interaction options of type typename using the provided rule

Parameters:
  • options (list) – list of parameterization options for a particular interaction

  • typename (str, optional) – string designation of interaction type, defaults to ‘dihedraltypes’

  • rule (str, optional) – string describing the selection rule, defaults to ‘stiffest’

Returns:

the selection parameterization option

Return type:

element of options (dict)

HTPolyNet.topology.typedata(h, s)[source]
HTPolyNet.topology.typeorder(a)[source]
typeorder correctly order the tuple of atom types for particular

interaction types to maintain sorted type dataframes

Parameters:

a (tuple) – tuple of atom indicies/types from a [ bond ], [ pair ], [ angle ], or [ dihedral ] record

Returns:

same atom indices/types correctly ordered to allow for easy searching/sorting

Return type:

tuple

HTPolyNet.unused_symmetry_stuff.add_enumerated_angles(self, newbonds, ignores=[], quiet=True)[source]
HTPolyNet.unused_symmetry_stuff.add_enumerated_dihedrals(self, newbonds, ignores=[], quiet=True)[source]
HTPolyNet.unused_symmetry_stuff.analyze_sea(deffnm, thresh=0.1)[source]
analyze_sea Builds and returns an atom-idx-ordered list of sea-cluster indexes.

Any two atoms with the same sea-cluster-index are considered symmetry equivalent. The main job of this method is to compute the time-averaged interatomic distance matrix. This matrix, if computed from a “hot” md simulation, should reveal atoms that are topologically symmetric, since the set of average interatomic distances from atom A to all other atoms and the set of average interatomic distances from atom B to all other atoms are the same if A and B are symmetry-equivalent.

Parameters:
  • deffnm (str) – gromacs mdrun deffnm

  • thresh (float, optional) – threshold value of euclidean norm of difference between rank-ordered distance matrix columns, defaults to 0.1

HTPolyNet.unused_symmetry_stuff.encluster(i, j, c)[source]

encluster enforce objects i and j to have the same cluster index c[i] and c[j]

Parameters:
  • i (int) – an index

  • j (int) – another index

  • c (list) – array of cluster indices

Returns:

True if i and j already have same cluster index, False otherwise

Return type:

bool

HTPolyNet.unused_symmetry_stuff.symm(d, thresh=0.1, outfile=None)[source]
symm Builds and returns an atom-idx-ordered list of sea-cluster indexes.

Any two atoms with the same sea-cluster-index are considered symmetry equivalent.

Parameters:
  • d (np.ndarray((N,N),float)) – interatomic distance matrix

  • thresh (float, optional) – threshold value of euclidean norm of difference between rank-ordered distance matrix columns, defaults to 0.1

  • outfile (str, optional) – name of outpufile, defaults to None

Returns:

symmetry set indices for each atom

Return type:

list

HTPolyNet.utils.clusters(G: Graph)[source]

clusters performs a clustering analysis and returns a histgram of cluster sizes (in numbers of molecules) as a pandas DataFrame

Parameters:

G (nx.Graph) – molecular connectivity graph

Returns:

cluster size histogram

Return type:

pd.DataFrame

HTPolyNet.utils.compute_E(strain, stress, fit_domain=[10, 100])[source]

compute_E compute the Young’s modulus by peforming a linear fit to an elastic regime in stress-vs-strain data

Parameters:
  • strain (numpy.array) – strain values

  • stress (numpy.array) – stress values

  • fit_domain (list, optional) – domain over which fit is made, defaults to [10,100]

Returns:

E and R2 from fit

Return type:

tuple(float,float)

HTPolyNet.utils.compute_tg(T, v, n_points=[10, 20])[source]

compute_tg peforms a Tg determination from (volume or density) vs temperature data by fitting lines to the low-T region and another to the high-T region, taking Tg as the temperature at which they intersect.

Parameters:
  • T (numpy.array) – temperature values

  • v (numpy.array) – volume or density data

  • n_points (list, optional) – number of points on the low and high side to fit lines to, defaults to [10,20]

HTPolyNet.utils.density_evolution(proj_dir)[source]

density_evolution returns a single dataframe containing density, temperture, number of bonds vs time by reading all edrs in the correct order from a complete project directory

Parameters:

proj_dir (str) – name of complete project directory

Returns:

the dataframe

Return type:

pandas.DataFrame

HTPolyNet.utils.density_from_gro(gro, mollib='./lib/molecules/parameterized', units='SI')[source]

density_from_gro computes density from a Gromacs gro file

Parameters:
  • gro (str) – name of gro file

  • mollib (str, optional) – location of parameterized molecular templates, defaults to ‘./lib/molecules/parameterized’

  • units (str, optional) – string indicating unit system, defaults to ‘SI’

Returns:

density

Return type:

float

HTPolyNet.utils.graph_from_bondsfile(bondsfile)[source]

graph_from_bondsfile generates a networkx Graph in which each node is a molecule (from ‘mi’ and ‘mj’ records in the bondsfile) and edges indicate two molecules are joined by a covalent bond

Parameters:

bondsfile (str) – name of bondsfile

Returns:

the graph

Return type:

networkx.Graph

HTPolyNet.utils.mwbxl(G: Graph, crosslinker='GMA', monomer='STY')[source]

mwbxl computes the histogram of monomer counts ‘n’ between crosslinking sites using a molecular connectivity graph; used mainly for vinyl-based polymerizations

Parameters:
  • G (nx.Graph) – molecular connectivity graph

  • crosslinker (str, optional) – name of crosslinker molecule, defaults to ‘GMA’

  • monomer (str, optional) – name of monomer, defaults to ‘STY’

Returns:

a dataframe of ‘n’ and ‘count’

Return type:

pd.DataFrame

HTPolyNet.utils.postsim_density_evolution(proj_dir, append_dirname=False)[source]

postsim_density_evolution returns a single dataframe that is a concatenation of the csv files in the ‘postsim’ subdirectories

Parameters:

proj_dir (str) – name of complete project directory

Returns:

the dataframe

Return type:

pandas.DataFrame