htpolynet package

htpolynet

Manages the HTPolyNet application, provides the command-line interface entry point.

Author: Cameron F. Abrams <cfa22@drexel.edu>

htpolynet.driver.cli()[source]

Command-line interface.

htpolynet.driver.fetch_example(args)[source]

Handles the fetch-example subcommand.

Parameters:

args (argparse.Namespace) – parsed arguments

htpolynet.driver.info(args)[source]

Handles the info subcommand.

Parameters:

args (argparse.Namespace) – parsed arguments

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

Handles the parameterize subcommand.

Parameters:

args (argparse.Namespace) – parsed arguments

htpolynet.driver.run(args)[source]

Handles the run subcommand.

Parameters:

args (argparse.Namespace) – parsed arguments

htpolynet.analysis

Handles the analyze subcommand.

Author: Cameron F. Abrams <cfa22@drexel.edu>

class htpolynet.analysis.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]

Handles executing the analysis.

parse_console_output()[source]
required_keys = ['command', 'subdir']
class htpolynet.analysis.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]

Parses a PostsimConfiguration file to build the list of stages to run.

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

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) – 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.analysis.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.analysis.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.analysis.analyze.analyze(args)[source]

Handles the analyze subcommand for managing gromacs-based trajectory analyses.

Parameters:

args (argparse.Namespace) – command-line arguments

Provides plotting functionality.

Author: Cameron F. Abrams <cfa22@drexel.edu>

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

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.analysis.plot.do_E_plots(phases, projdirs, outfile='e.png', fit_domain=[10, 200], save_data='E.csv')[source]
htpolynet.analysis.plot.do_tg_plots(phases, projdirs, outfile='tg.png', save_data='data.csv', n_points=[10, 20])[source]
htpolynet.analysis.plot.global_trace(df, names, outfile='plot.png', transition_times=[], markers=[], interval_labels=[], y2names=[], **kwargs)[source]

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) – name of output image file, defaults to ‘plot.png’

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

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

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

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

htpolynet.analysis.plot.init_molecule_graph(proj_dir)[source]

Creates and initializes an 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.analysis.plot.multi_trace(dfL, xnames, ynames, labels=[], xlabel='time [ps]', ylabel='', outfile='plot.png', **kwargs)[source]

Generates a plot of each y vs x in df.

Parameters:
  • dfL (list of pandas.DataFrame) – list of dataframes, one per trace

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

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

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

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

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.analysis.plot.plots(args)[source]

Handles the plots subcommand.

Parameters:

args (argparse.Namespace) – command-line arguments

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

Generic scatter plot generator.

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

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

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

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

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

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) – name of output image file, defaults to ‘plot.png’

Returns:

the list of average values

Return type:

list

Handles the postsim subcommand.

Author: Cameron F. Abrams <cfa22@drexel.edu>

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

Bases: PostSimMD

a class to handle temperature annealing MD simulation

build_mdp(mdpname, **kwargs)[source]

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.analysis.postsim.PostSimDeform(indict, strict=True)[source]

Bases: PostSimMD

a class to handle a uniaxial deformation MD simulation

build_mdp(mdpname, **kwargs)[source]

Builds the GROMACS mdp file required for a uniaxial deformation 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.analysis.postsim.PostSimLadder(indict, strict=True)[source]

Bases: PostSimMD

a class to handle a temperature-ladder MD simulation

build_mdp(mdpname, **kwargs)[source]

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.analysis.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]

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]

Handles executing the postsim MD simulation.

Parameters:

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

class htpolynet.analysis.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.analysis.postsim.PostSimAnneal'>, 'deform': <class 'htpolynet.analysis.postsim.PostSimDeform'>, 'equilibrate': <class 'htpolynet.analysis.postsim.PostSimMD'>, 'ladder': <class 'htpolynet.analysis.postsim.PostSimLadder'>}
parse(**kwargs)[source]

Parses a PostsimConfiguration file to build the list of stages to run.

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

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) – 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.analysis.postsim.postsim(args)[source]

Handles the postsim subcommand for managing post-cure production MD simulations.

Parameters:

args (argparse.Namespace) – command-line arguments

Various utility methods for plotting and postprocessing.

Author: Cameron F. Abrams <cfa22@drexel.edu>

htpolynet.analysis.utils.clusters(G: Graph)[source]

Performs a clustering analysis and returns a histogram 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.analysis.utils.compute_E(strain, stress, fit_domain=[10, 100])[source]

Computes the Young’s modulus by performing 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) – domain over which fit is made, defaults to [10,100]

Returns:

E and R2 from fit

Return type:

tuple(float,float)

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

Performs 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) – number of points on the low and high side to fit lines to, defaults to [10,20]

htpolynet.analysis.utils.density_evolution(proj_dir)[source]

Returns a single dataframe containing density, temperature, 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.analysis.utils.density_from_gro(gro, mollib='./lib/molecules/parameterized', units='SI')[source]

Computes density from a Gromacs gro file.

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

  • mollib (str) – location of parameterized molecular templates, defaults to ‘./lib/molecules/parameterized’

  • units (str) – string indicating unit system, defaults to ‘SI’

Returns:

density

Return type:

float

htpolynet.analysis.utils.graph_from_bondsfile(bondsfile)[source]

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.analysis.utils.mwbxl(G: Graph, crosslinker='GMA', monomer='STY')[source]

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) – name of crosslinker molecule, defaults to ‘GMA’

  • monomer (str) – name of monomer, defaults to ‘STY’

Returns:

a dataframe of ‘n’ and ‘count’

Return type:

pd.DataFrame

htpolynet.analysis.utils.postsim_density_evolution(proj_dir, append_dirname=False)[source]

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

htpolynet.core

Class for managing gromacs .gro file data.

Author: Cameron F. Abrams <cfa22@drexel.edu>

class htpolynet.core.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]

Computes bond lengths for bonds in bdf and stores results in a new column.

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

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

atomcount()[source]

Returns the number of atoms in the Coordinates object.

Returns:

number of atoms

Return type:

int

checkbox()[source]

Checks that all atom positions fit within the designated box.

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]

Copies 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]

Decrements value of z attributes of all atoms found in pairs.

Parameters:

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

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

Deletes atoms whose global indices appear in idx.

If reindex is True, global indices are recalculated to be sequential starting at 1 with no gaps, and two new columns are added: ‘oldGlobalIdx’ (pre-deletion indices) and ‘globalIdxShift’ (change from old to new index for each atom).

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

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

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

Generates a Coordinates object that represents an FCC crystal.

Parameters:
  • a (float) – lattice parameter

  • nc (list) – 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]

Identifies all appropriate sacrificial hydrogen atoms for the given bond pairs.

Parameters:
  • pairs (list) – list of (ai, aj, order) tuples indicating bonds

  • T (Topology) – the global Topology

  • rename (bool) – if True, renames remaining H atoms so highest-order named H atoms appear sacrificed, defaults to False

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

Returns:

global atom indices to delete

Return type:

list

geometric_center()[source]

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]

Returns the cartesian position of atom with global index idx.

Parameters:

idx (int) – global index of atom

Returns:

cartesian position of the atom

Return type:

numpy.ndarray

get_atom_attribute(name, attributes)[source]

Returns values of attributes listed in name from atoms specified by attribute:value pairs.

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

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

Returns:

one or more return attribute values (list if name is a list; scalar otherwise)

Return type:

list or scalar

get_atoms_w_attribute(name, attributes)[source]

Returns rows of atoms dataframe with columns named in name for atoms matching attributes.

Parameters:
  • name (list) – attribute names for the columns to be returned

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

Returns:

matching dataframe segment

Return type:

pd.DataFrame

get_idx(attributes)[source]

Returns the global atom index of the atom identified by the given attributes.

Parameters:

attributes (dict) – 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]

Returns True if all atoms in the atoms dataframe have the given attributes.

Parameters:

attributes (list) – attribute names to look for

Returns:

True if all atoms have all 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

  • indices (list) – atom global indices to transform; if empty, transforms all, defaults to []

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

Initializes link-cell structure for ring-pierce testing.

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

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

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

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

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

linkcelltest(i, j)[source]

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]

Merges two Coordinates objects.

Parameters:

other (Coordinates) – the other Coordinates object

Returns:

integer shifts in atom index, bond index, and residue index

Return type:

tuple

mic(r, pbc)[source]

Applies minimum image convention to displacement vector r.

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

  • pbc – periodic boundary condition flags

Returns:

minimum-image displacement vector

Return type:

np.ndarray(3,float)

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

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

Parameters:
  • other (Coordinates) – other Coordinates instance

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

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

Returns:

distance between the two atoms (one from self, one from other) that are closest together

Return type:

float

minmax()[source]

Returns the lower-leftmost and upper-rightmost positions in the atoms dataframe.

Returns:

lower-leftmost and upper-rightmost points, respectively

Return type:

tuple(np.ndarray, np.ndarray)

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]

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) – list of attributes to take, defaults to [] (take all)

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

Reads a Gromacs gro file.

Parameters:

filename (str) – name of gro file

Returns:

a new Coordinates instance

Return type:

Coordinates

classmethod read_mol2(filename)[source]

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]

Returns an ordered list of bond lengths for bonds in bdf.

Parameters:

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

Returns:

atom distances

Return type:

list

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

Computes distance between atoms i and j.

Returns:

distance between i and j

Return type:

float

rotate(R)[source]

Rotates all coordinate vectors by rotation matrix R.

Parameters:

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

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

Finds the two H atoms (one bound to ai, one 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) – whether to rename remaining H atoms so highest-sorted named H atoms appear found, defaults to False

Returns:

global indexes of the two sacrificial H atoms

Return type:

list

set_atom_attribute(name, value, attributes)[source]

Sets the attributes named in name to the given values for atoms matching attributes.

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

  • value (list) – values of attributes to set (parallel to name)

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

set_atomset_attribute(attribute, srs)[source]

Sets attribute of atoms to srs.

Parameters:
  • attribute (str) – name of attribute

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

set_box(box: ndarray)[source]

Sets the box size from box.

Parameters:

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

show_z_report()[source]

Generates a text-based histogram of atom z-values (0–3), keyed by resname:atomname.

spew_atom(attributes)[source]

Outputs all attributes of atom identified by the attributes dict.

Parameters:

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

Returns:

stringified dataframe row

Return type:

str

subcoords(sub_adf: DataFrame)[source]

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) – 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]

Translates all coordinate vectors by displacement vector L.

Parameters:

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

unwrap(P, O, pbc)[source]

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:

np.ndarray(3,float)

wrap_coords()[source]

Wraps all atomic coordinates into box.

wrap_point(ri)[source]

Wraps point ri into the central periodic image.

Parameters:

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

Returns:

the wrapped point and number of box lengths required to wrap this point, per dimension

Return type:

tuple

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

Writes atom attributes to a file.

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

  • filename (str) – name of file to write

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

Raises:

Exception – if any item in attributes does not exist in the coordinates dataframe

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

Writes coordinates and, if present, velocities to a GROMACS-format coordinate file.

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

  • grotitle (str) – title line for the .gro file, defaults to ‘’

write_mol2(filename, bondsDF=Empty DataFrame Columns: [] Index: [], molname='', other_attributes=Empty DataFrame Columns: [] Index: [])[source]

Writes a mol2-format file from coordinates and an optional bonds DataFrame.

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

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

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

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

htpolynet.core.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.core.coordinates.dfrotate(df: DataFrame, R)[source]

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

Manages generation of molecular templates.

Author: Cameron F. Abrams <cfa22@drexel.edu>

class htpolynet.core.molecule.Molecule(name='', generator: Reaction = None, origin: str = None)[source]

Bases: object

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

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 directives 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]

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

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]

Wrapper for the TopoCoord.center_coords method.

Parameters:

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

create_new_stereoisomers()[source]

Generates new molecules to hold stereoisomers of self.

Returns:

returns early if no action taken

Return type:

None

determine_sequence(moldict)[source]

Recursively determines 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]

Flips stereochemistry of atoms in idxlist.

Parameters:

idxlist (list) – global indices of chiral atoms

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

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]

Generates list of Molecule shells, one for each stereoisomer.

Returns:

returns early if no stereoisomers need to be generated

Return type:

None

get_angles_dihedrals(bond)[source]

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

Parameters:

bond – 2-element list-like container of ints

Raises:

Exception – if a NaN is found in any selection

Returns:

copies of the dataframe selections for angles, dihedrals, and 1-4 pairs

Return type:

tuple

get_molecular_weight()[source]

Returns the molecular weight of self.

Returns:

molecular weight in g/mol

Return type:

float

get_origin()[source]

Returns the value of the origin member.

Returns:

value of origin member

get_resname(internal_resid)[source]

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]

Computes the mapping dictionary from molecule template index to instance index in the other TopoCoord.

Parameters:
  • otherTC (TopoCoord) – the other TopoCoord

  • other_bond – 2 atom indices of the bond in the other TopoCoord

  • bystanders – bystander lists, one for each reacting atom

  • oneaways – 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

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]

Generates 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]

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) – enumerated parameter indicating reaction_stage

merge(other)[source]

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]

Manages invocation of vacuum minimization.

Parameters:

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

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

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]

Populates the bond templates and reaction bonds for self.

Parameters:

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

previously_parameterized()[source]

Returns True if a gro file exists in the project molecule/parameterized directory for this molecule.

Returns:

True if gro file found

Return type:

bool

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

Reads 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]

Manages invocation of MD relaxations.

Parameters:

relax_dict (dict) – dictionary of simulation directives

rotate_bond(a, b, deg)[source]

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 in degrees

set_gro_attribute(attribute, srs)[source]

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

Parameters:
  • attribute (str) – name of attribute

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

set_origin(value)[source]

Sets the value of the origin member.

Parameters:

value – value to assign

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]

Sets 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]

Given a composite molecule, translates and rotates the piece downstream of the yet-to-be-created bond 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) – resid of left-hand residue

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

  • from_resid (int) – resid 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 of the sacrificial hydrogens

Return type:

tuple

update_zrecs(zrecs, moldict)[source]

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 (dict) – dictionary of available molecules

write_gro_attributes(attribute_list, grxfilename)[source]

Writes atomic attributes to a file.

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

  • grxfilename (str) – name of output file

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

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.core.molecule.generate_symmetry_reactions(RL: list[Reaction], MD: dict[str, Molecule])[source]

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.core.molecule.yield_bonds(R: Reaction, TC: TopoCoord, resid_mapper)[source]

For each bond pattern in the reaction R, yields 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

Yields:

ReactionBond – a reaction bond

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

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

Class for jointly handling Topology and Coordinate objects.

Author: Cameron F. Abrams <cfa22@drexel.edu>

class htpolynet.core.topocoord.BTRC(*values)[source]

Bases: Enum

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

failed_pierced_ring = 1
failed_shortcircuit = 2
passed = 0
unset = 99
class htpolynet.core.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]

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) – 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) – dataframe with ai, aj, initial-distance columns

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

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

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

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

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

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

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

are_bonded(i, j)[source]

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]

Checks 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]

Alters 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 with columns ‘ai’, ‘aj’, ‘initial_distance’

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

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

  • minimum_distance (float) – minimum bond length allowed, overriding type-specific b0, defaults to 0.0

  • init_colname (str) – name of column with initial distances, defaults to ‘initial_distance’

attenuate_pair_parameters(pairdf, i, n, draglimit_nm=0.3)[source]

Alters 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 with columns ‘ai’, ‘aj’, ‘initial_distance’

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

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

  • draglimit_nm (float) – lower limit of interatomic distance requested from drag, defaults to 0.3

bondcycle_collective(bdf: DataFrame)[source]

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

Parameters:

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

Returns:

bond records that results in no new bondcycles

Return type:

pandas.DataFrame

bondtest(b, pbc=[1, 1, 1], show_piercings=True)[source]

Determines if bond b is to be allowed to form based on geometric and topological criteria.

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

  • pbc (list) – 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, defaults to True

Returns:

BTRC enum instance

Return type:

BTRC

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

Applies bond filters to all bonds in the dataframe.

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

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

  • show_piercings (bool) – 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]

Centers all coordinates in box.

Parameters:

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

check_your_topology()[source]

Checks topology for duplicate 1-4 pair interactions and deletes them.

checkbox()[source]

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

Returns:

(bool, bool), True for each of lower-leftmost and upper-rightmost points if they are within the box

Return type:

tuple

copy_bond_parameters(bonds)[source]

Generates and returns 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]

Copies coordinates and box size from other to self.

Parameters:

other (TopoCoord) – a TopoCoord instance

count_H(idx)[source]

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]

Subtracts one from attribute att_name of all atoms identified by attribute:value pairs in attribute_dict.

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

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

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]

Returns system density.

Parameters:

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

Returns:

density

Return type:

float

enumerate_1_4_pairs(at_idx)[source]

Enumerates 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]

Performs an MD simulation using mdrun.

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

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

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

Returns:

list of edr files this equilibration generates

Return type:

list

flip_stereocenters(idxlist)[source]

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]

Returns the cartesian position of atom with global index idx.

Parameters:

idx (int) – atom global index

Returns:

position of atom as array of shape (3,)

Return type:

numpy.ndarray

get_bystanders(atom_idx)[source]

Identifies and returns bystanders at a particular proposed bond specified by atom_idx.

Parameters:

atom_idx – 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]

Returns values of attributes listed in att_name from atoms specified by attribute:value pairs in attribute_dict.

Parameters:
  • att_name – name or list of names 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:

one or more return attribute values (list if att_name is a list; scalar otherwise)

Return type:

scalar or list

get_gro_attributelist_by_attributes(attribute_list, attribute_dict)[source]

Returns all rows of atoms dataframe and columns named in attribute_list for atoms identified by the attribute_dict.

Parameters:
  • attribute_list (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]

Identifies and returns 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]

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]

Using absolute pathname information, grabs the most up-to-date gromacs files for this system and deposits them into the cwd.

gro_DataFrame(name)[source]

Returns 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.core.topocoord (INFO)>>, **kwargs)[source]

Manages invoking a single Gromacs run using the current TopoCoord.

Parameters:
  • out (str) – output filename basename

  • mdp (str) – name of mdp file

  • mylogger – 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]

Adds 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]

Copies non-Gromacs-standard atom attributes from molecule templates in molecule_dict according to molecule counts in dict initial_composition.

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

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

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

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

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

interresidue_partners_of(i)[source]

Returns 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]

Removes linkcell_idx attribute from Coordinate.A.

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

Initializes 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, defaults to 1

  • force_repopulate (bool) – if True, force repopulation of the linkcell structure, defaults to True

load_files(filenames: dict)[source]

Loads 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

  • explicit_sacH (dict) – explicit mapping of sacrificial H atoms, defaults to {}

Returns:

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

Return type:

list

make_resid_graph(json_file=None)[source]

Makes a residue connectivity graph.

Parameters:

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

makes_shortcircuit(i, j)[source]

Determines 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 with columns ‘ai’, ‘aj’, ‘reactantName’

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

  • overcharge_threshhold (float) – threshold for charge adjustment, defaults to 0.1

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

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

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

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

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

  • Exception – if nan found in any system pair

maxspan()[source]

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]

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]

Computes the distance of closest approach between self’s Coordinates and other’s Coordinates.

Parameters:
  • other (TopoCoord) – another TopoCoord object

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

  • other_excludes (list) – 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]

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

Returns:

two numpy arrays, lower-leftmost and upper-rightmost positions, respectively

Return type:

tuple

overwrite_coords(other)[source]

Overwrites coordinates in self by those in other.

Parameters:

other (TopoCoord) – another TopoCoord object

partners_of(i)[source]

Returns 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]

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 atom

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

  • show_piercings (bool) – 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]

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

  • preserve_box (bool) – if True, preserve the existing box, defaults to False

  • wrap_coords (bool) – if True, wrap coordinates into the box, defaults to False

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

Reads attributes from file into self.Coordinates.A.

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

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

read_mol2(mol2filename, **kwargs)[source]

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 performed.

Parameters:

mol2filename (str) – name of mol2 file

read_top(topfilename)[source]

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]

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]

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

Parameters:

pairsdf (pandas.DataFrame) – dataframe of pairs with columns ‘ai’, ‘aj’

reset_grx_attributes_from_idx_list(list_name)[source]

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]

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

Parameters:

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

resid_partners_of(ri)[source]

Returns 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]

Restores saved bond parameters in df saved by overwriting.

Parameters:

saved (pandas.DataFrame) – bonds dataframe

return_bond_lengths(bdf)[source]

Returns the length of all bonds in bdf.

Parameters:

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

Returns:

list of lengths parallel to bonds

Return type:

list

rotate(R)[source]

Applies rotation matrix R to all atom positions.

Parameters:

R (numpy.ndarray) – rotation matrix of shape (3, 3)

set_gro_attribute(attribute, srs)[source]

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

Parameters:
  • attribute (str) – name of attribute

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

set_gro_attribute_by_attributes(att_name, att_value, attribute_dict)[source]

Sets the attribute named att_name to att_value for the set of atoms specified by attribute_dict.

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

  • att_value – value to set the attribute to

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

set_grx_attributes(attributes=[])[source]

Overrides the global GRX_ATTRIBUTES.

Parameters:

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

swap_atom_names(ai, aj)[source]

Swaps the names of the two atoms with global indices ai and aj. This is used when automatically selecting which of several possible sacrificial H’s will actually be selected. Surviving H’s are renamed so it always appears that the H with the “least important” name (lowest order if sorted) is the sacrificial H, giving 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]

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

Parameters:

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

Returns:

mass

Return type:

float

total_volume(units='SI')[source]

Returns total volume represented by the system’s Coordinates.

Parameters:

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

Returns:

box volume

Return type:

float

translate(L)[source]

Applies translation vector L to all atom positions.

Parameters:

L (numpy.ndarray) – translation vector of shape (3,)

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

Updates global topology and necessary atom attributes in the configuration to reflect formation of all bonds listed in bdf.

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

  • template_dict (dict) – dictionary of molecule templates keyed on molecule name, defaults to {}

  • write_mapper_to (str) – filename to write index mapper to, defaults to None

Returns:

bonds dataframe and pairs dataframe with atom indices updated to reflect any atom deletions

Return type:

tuple

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

The minimize analog to grompp_and_mdrun; performs an energy minimization using mdrun.

Parameters:

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

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

Performs a vacuum MD simulation using mdrun.

Parameters:

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

wrap_coords()[source]

Wraps all coordinates into center periodic box.

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

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

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

  • grotitle (str) – title to put in gro file, defaults to ‘’

write_gro_attributes(attributes_list, grxfilename)[source]

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]

Writes GRX attributes to a file.

Parameters:

grxfilename (str) – name of output file

write_mol2(filename, molname='', element_names_as_types=False)[source]

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) – name of molecule to put in mol2 file, defaults to ‘’

  • element_names_as_types (bool) – if True, use element names as atom types, defaults to False

write_top(topfilename)[source]

Writes 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.core.topocoord.find_template(BT: BondTemplate, moldict)[source]

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 molecules

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

Class for managing gromacs .top file data.

Author: Cameron F. Abrams <cfa22@drexel.edu>

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

Bases: object

Class for handling gromacs top data

add_bonds(pairs=[])[source]

Adds bonds indicated in list pairs to the topology.

Parameters:

pairs (list) – list of (ai, aj, order) tuples, defaults to []

Raises:

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

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

Adds type-6 (non-topological) bonds to help drag atoms toward each other.

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

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

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

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

Adjusts atom partial charges so that total system charge equals the desired value.

Parameters:
  • atoms (list) – global atom indices to adjust, defaults to []

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

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

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

Returns:

self

Return type:

Topology

atomcount()[source]

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]

Alters the kb and b0 parameters for new crosslink bonds according to the values prior to relaxation, 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/x of the way from its maximum value to its equilibrium value.

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

  • 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 (float) – minimum bond length allowed, overriding type-specific b0 if greater than 0

attenuate_pair_parameters(pairsdf, stage, max_stages, draglimit_nm=0.3)[source]

Alters the kb and b0 parameters for new pre-crosslink pairs according to the values prior to dragging, the desired lower limit of interatomic distance, and the ratio stage/max_stages.

Parameters:
  • pairsdf (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]

Checks that the ‘bonds’ and ‘mol2_bonds’ dataframes contain the same bonds.

build_interresidue_graph(G, ri)[source]
copy_bond_parameters(bonds)[source]

Generates and returns 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]

Deletes atoms from topology.

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

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

  • return_idx_of (list) – old indices whose new indices should be returned, defaults to []

Returns:

old-index-to-new-index mapper

Return type:

dict

detect_rings()[source]

Detects unique rings in the topology.

dup_check(die=True)[source]

Checks for duplicate type-like topology records.

Parameters:

die (bool) – if True, raise an exception when a duplicate is found, defaults to True

Raises:

Exception – if a duplicate type with different parameters is detected and die is True

classmethod from_ex(other)[source]

Makes a new Topology instance by copying only the extensive dataframes from an existing topology.

Parameters:

other (Topology) – the other topology

Returns:

a new Topology built from the extensive dataframes of other

Return type:

Topology

get_atom_attribute(idx, attribute)[source]

Returns value of attribute of atom idx.

Parameters:
  • idx (int) – global atom index

  • attribute (str) – atom attribute name

Returns:

atom attribute value

get_atomtype(idx)[source]

Gets atom type of atom with global index idx.

Parameters:

idx (int) – atom global index

Returns:

atom type

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:

tuple

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

Merges another topology into self.

Parameters:

other (Topology) – topology to merge in

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

Merges type-like topology dataframes from other to self.

Parameters:

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

null_check(msg='')[source]

Checks for NaNs in dataframe locations that should never have NaNs.

Parameters:

msg (str) – context message, defaults to ‘’

Raises:

Exception – if a NaN is found in a required field

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

Reads a GROMACS-style topology file and returns a Topology instance.

Each directive section is stored as a pandas DataFrame. Duplicate ‘dihedrals’ and ‘dihedraltypes’ sections are merged.

Parameters:
  • filename (str) – name of GROMACS top file to read

  • pad (float) – padding value for missing fields, defaults to _PAD_

Raises:

KeyError – if an unrecognized topology directive is encountered

Returns:

a new Topology instance

Return type:

Topology

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

Removes all non-topological restraint bonds represented in pairdf.

Deleting these bonds does not influence angles or dihedrals.

Parameters:

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

rep_ex(count=0)[source]

Replicates extensive topology components (atoms, pairs, bonds, angles, dihedrals).

Parameters:

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

Raises:

Exception – 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]

Copies 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]

Shifts all atom indexes in a topology directive dataframe.

Parameters:
  • idxshift (int) – integer index shift

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

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

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

total_charge()[source]

Computes and returns total system charge.

Returns:

total system charge

Return type:

float

total_mass(units='gromacs')[source]

Returns total mass of all atoms in the Topology.

Parameters:

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

Returns:

total mass in amu (gromacs) or kg (SI)

Return type:

float

write_top(filename)[source]

Writes topology to a GROMACS-format top file.

Parameters:

filename (str) – name of top file to write

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

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.core.topology.idxorder(a)

Correctly orders the tuple of atom types for particular interaction types.

Parameters:

a (tuple) – atom indices/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.core.topology.repeat_check(t, msg='')[source]

Checks for repeated index tuples.

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

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

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

Selects 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) – string designation of interaction type, defaults to ‘dihedraltypes’

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

Returns:

the selected parameterization option (an element of options)

Return type:

dict

htpolynet.core.topology.typedata(h, s)[source]
htpolynet.core.topology.typeorder(a)[source]

Correctly orders the tuple of atom types for particular interaction types.

Parameters:

a (tuple) – atom indices/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.cure

Manages bond templates (bonds defined by type) and reaction bonds (bonds defined by instances).

Author: Cameron F. Abrams <cfa22@drexel.edu>

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

Bases: object

is_reverse_of(other)[source]

Returns 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]

Reverses the order of all parallel lists in a BondTemplate object.

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

Bases: object

reverse()[source]
class htpolynet.cure.chain.Chain(head=-1, tail=-1, idx=-1)[source]

Bases: object

is_head(a)[source]
is_tail(a)[source]
merge(other)[source]
remap_idx(idx_mapper)[source]
shift(shift)[source]
class htpolynet.cure.chain.ChainManager(**kwargs)[source]

Bases: object

chain_of(a)[source]
from_dataframe(D, lidx_col='bondchain_idx', gidx_col='bondchain')[source]
injest_bond(ai, aj)[source]
injest_bonds(bondlist)[source]
injest_other(other)[source]
mergechains(dst, src)[source]
new_chain(head, tail)[source]
reindex()[source]
remap(idx_mapper)[source]
shift(shift)[source]
to_dataframe(D, lidx_col='bondchain_idx', gidx_col='bondchain')[source]

Manages execution of the CURE algorithm.

Author: Cameron F. Abrams <cfa22@drexel.edu>

class htpolynet.cure.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]

Manages generation of all capping bonds.

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

  • RL (ReactionList) – list of all reaction types

  • MD (MoleculeDict) – dictionary of all molecule information

  • gromacs_dict (dict) – 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]

Performs one CURE iteration.

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

  • RL (ReactionList) – list of all reaction types

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

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

Returns:

dictionary of resulting output file names

Return type:

dict

is_cured()[source]

Returns True if system is cured.

Returns:

True if system is cured; False otherwise

Return type:

bool

next_iter()[source]

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]

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]

Sets up this CureController object.

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

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

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

class htpolynet.cure.curecontroller.CureState[source]

Bases: object

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

Returns a new CureState object generated by reading in the YAML file.

Parameters:

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

Returns:

new CureState object returned by yaml.load

Return type:

CureState

reset()[source]

Resets this CureState object to begin a new CURE iteration.

class htpolynet.cure.curecontroller.cure_step(*values)[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

Handles expansion of reactions based on chains.

Author: Cameron F. Abrams <cfa22@drexel.edu>

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

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.

Parameters:

molecules (MoleculeDict) – dictionary of molecular templates constructed from explicit declarations

Returns:

the list of new reactions and dictionary of new molecules

Return type:

tuple(ReactionList, MoleculeDict)

Handles Reaction objects.

Author: Cameron F. Abrams <cfa22@drexel.edu>

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

Bases: object

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

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) – flag to plot the reaction network, defaults to True

Returns:

ordered list of tuples, each of the form (name-of-product-molecule, Reaction)

Return type:

list of tuples

htpolynet.cure.reaction.generate_product_name(R: Reaction)[source]

Automatically generates 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.cure.reaction.get_r(mname, RL: list[Reaction])[source]

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 None

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

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) – stage of reactions to search, defaults to reaction_stage.cure

Returns:

True if molecule is a reactant, False otherwise

Return type:

bool

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

Determines 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.cure.reaction.parse_reaction_list(baselist: list[Reaction])[source]

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.cure.reaction.product_sequence_resnames(R: Reaction, reactions: list[Reaction])[source]

Recursively generates 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.cure.reaction.reactant_resid_to_presid(R: Reaction, reactantName: str, resid: int, reactions: list[Reaction])[source]

Maps the resid of a reactant monomer to its inferred resid in the associated 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.cure.reaction.reaction_stage(*values)[source]

Bases: Enum

Enumerated reaction stage

build = 0
cap = 3
cure = 2
param = 1
unset = 99

Handles the HTPolyNet runtime workflow.

Author: Cameron F. Abrams <cfa22@drexel.edu>

class htpolynet.cure.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]

Manages CURE algorithm execution.

Returns:

only returns None if CURE cannot execute

Return type:

None

do_densification(deffnm='densified')[source]

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:

deffnm (str) – deffnm prefix fed to gmx mdrun, defaults to ‘densified’

Returns:

dictionary of Gromacs file names

Return type:

dict

do_initialization(inpfnm='init')[source]

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

Parameters:

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

Returns:

dictionary of Gromacs files

Return type:

dict

do_postcure()[source]

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

Returns:

dictionary of Gromacs file names

Return type:

dict

do_precure()[source]

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]

Manages creation and parameterization of all monomers and oligomer templates.

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

  • force_checkin (bool) – 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]

Writes ‘gro’, ‘top’, ‘tpx’, and ‘grx’ files for system.

Parameters:

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

Returns:

dictionary of Gromacs file basenames

Return type:

dict

htpolynet.cure.runtime.logrotate(filename)[source]

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

Parameters:

filename (str) – name of log file

htpolynet.external

Manages execution of AmberTools antechamber, parmchk2.

Author: Cameron F. Abrams <cfa22@drexel.edu>

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

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) – format of input structure file, defaults to ‘mol2’; ‘pdb’ is other option

Raises:

parmed.exceptions.GromacsError – if parmed fails

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

Bases: object

linelen = 55
run(override=(), ignore_codes=[], quiet=True)[source]

Methods for handling the gmx suite of executables.

Author: Cameron F. Abrams <cfa22@drexel.edu>

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

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.external.gromacs.gmx_command(name, options={}, console_in='')[source]
htpolynet.external.gromacs.gmx_energy_trace(edr, names=[], report_averages=False, keep_files=False, **kwargs)[source]

Generates traces of data in edr file.

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

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

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

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

Returns:

dataframe of traces

Return type:

pandas.DataFrame

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

Uses ‘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) – name of column in idf where distances are stored, defaults to ‘r’

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

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

Returns:

list of distances parallel to idf columns

Return type:

numpy.ndarray

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

Launcher for grompp and mdrun.

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

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

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

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

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

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

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

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) – directory to search for input structures, defaults to ‘.’

Raises:

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

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

Modifies 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) – name of output file, defaults to None

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

htpolynet.external.gromacs.mdp_to_dict(mdp_filename)[source]

Handles identification of available software needed by HTPolyNet.

Author: Cameron F. Abrams <cfa22@drexel.edu>

htpolynet.external.software.info()[source]

Logs the software version info.

htpolynet.external.software.set_gmx_preferences(parameters)[source]

Sets the global Gromacs preferences.

Parameters:

parameters (dict) – dictionary from cfg file

htpolynet.external.software.sw_setup()[source]

Checks that all required AmberTools executables are accessible and queries their version.

htpolynet.external.software.to_string()[source]

Returns a formatted string listing AmberTools, GROMACS, and GPU info.

htpolynet.geometry

Manages bidirectional interatomic bondlists.

Author: Cameron F. Abrams <cfa22@drexel.edu>

class htpolynet.geometry.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]

Generates and returns an adjacency matrix built from the bondlist.

Returns:

adjacency matrix

Return type:

numpy.ndarray

append(pair)[source]

Appends the bonded pair in parameter ‘pair’ to the bondlist.

Parameters:

pair (list-like container) – pair atom indices

are_bonded(idx, jdx)[source]

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]

Recursively builds 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]

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]

Generates a networkx Graph object from the bondlist.

Returns:

a networkx Graph object

Return type:

networkx.Graph

half_as_list(root, depth)[source]

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]

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]

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

Manages the link-cell structure used for searching for pierced rings.

Author: Cameron F. Abrams <cfa22@drexel.edu>

class htpolynet.geometry.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]

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]

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]

Tests 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 if C is in the linkcell structure, False otherwise

Return type:

bool

cellndx_of_ldx(i)[source]

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]

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]

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]

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

Parameters:
  • cutoff (float) – cutoff distance

  • box (numpy.ndarray) – box size

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

ldx_of_cellndx(C)[source]

Returns 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]

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]

Populates the neighborlist member, one element per cell; each element is the list of neighbors of that cell.

neighbors_of_cellndx(Ci)[source]

Returns the list of neighbors of cell Ci by their (i,j,k) indices.

Parameters:

Ci (numpy.ndarray) – (i,j,k) cell index

Returns:

list of (i,j,k) indices of neighbor cells

Return type:

list

point_in_cellndx(R, C)[source]

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 if R is in C, False otherwise

Return type:

bool

populate(Coordinates, ncpu=1)[source]

Populates linkcell structure.

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

  • ncpu (int) – 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]

Populates 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]

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.geometry.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]

Handles ring-piercing determinations.

Author: Cameron F. Abrams <cfa22@drexel.edu>

class htpolynet.geometry.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 (numpy.ndarray) – 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 (bool, 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.geometry.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.geometry.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.geometry.ring.lawofcos(a, b)[source]

Returns 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

htpolynet.utils

htpolynet.utils.banner.banner(logf)[source]

Implements a simple checkpointing scheme using a wrapper.

Author: Cameron F. Abrams <cfa22@drexel.edu>

class htpolynet.utils.checkpoint.Checkpoint(input_dict={})[source]

Bases: object

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

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

Parameters:

method – name of method to be wrapped

Returns:

wrapped method

Return type:

method

htpolynet.utils.checkpoint.read_checkpoint()[source]

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

Some convenient tools for handling pandas dataframes in the context of htpolynet coordinates.

Author: Cameron F. Abrams <cfa22@drexel.edu>

htpolynet.utils.dataframetools.get_row(df: DataFrame, attributes: dict)[source]

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

htpolynet.utils.dataframetools.get_row_as_string(df: DataFrame, attributes)[source]

Returns the selected rows as a string, with rows 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.utils.dataframetools.get_row_attribute(df: DataFrame, name, attributes)[source]

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.utils.dataframetools.get_rows_w_attribute(df: DataFrame, name, attributes: dict)[source]

Returns a series of values of attribute “name” from all rows matching attributes dict.

Returns:

list of values from selected rows

Return type:

values

htpolynet.utils.dataframetools.set_row_attribute(df: DataFrame, name, value, attributes)[source]

Sets 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.utils.dataframetools.set_rows_attributes_from_dict(df: DataFrame, valdict, attributes)[source]

Sets 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

Manages the inputcheck subcommand.

Author: Cameron F. Abrams <cfa22@drexel.edu>

htpolynet.utils.inputcheck.input_check(args)[source]

Manages the input-check subcommand.

Parameters:

args (argparse.Namespace) – parsed arguments

htpolynet.utils.stringthings.my_logger(msg, logf, width=67, fill='*', sep=', ', just='^')[source]