Composite

Overview

hoobas.Composite.deferred Decorator to defer function calls until the object is built
hoobas.Composite.CompositeObject Class that handles topology information of building blocks of hoobas and keeps track of force-field constants
hoobas.Composite.AttachmentSite
hoobas.Composite.TopologyType Base bonded force-field topology type which defines the base variables of every bonded type.
hoobas.Composite.TopologyItem Defines a topology item, for instance, a bond

Details

class hoobas.Composite.Angle(ilist=None)[source]
class hoobas.Composite.AngleType(name='', topodict=None, unitdict=None)[source]

A default class for anglular potentials. Has topology constants of energy_constants (E) and angle_constant (1)

class hoobas.Composite.AttachmentSite(index, qualifier=None, bound_to=None, orientation=None, restriction=None)[source]
class hoobas.Composite.BeadList[source]

Object to manage and link the list of beads and a numpy array;

Attributes:
_beads: list of bead objects _positions: N x 3 numpy array of all the bead positions _references: dictionary of objects which positions are linked with, but are also part of another BeadList graph: a directed networkx graph that keeps track of which subunit beads belong to

Note: the bead positions (bead[i].position) has the same reference as the position array (self._position[i,:])

Methods:
relink(): resets all the bead position references to the _position array change_units(new): change all the units of this object to the SimulationUnits new __iter__(): yields the beads in the beadlist __getitem__(index): returns the bead at index __len__: returns the length of the bead array
Properties:
positions(): returns _positions positions(arr): sets the contents of _positions to arr, but keeps the reference beads(): returns the list of beads in self._beads
class hoobas.Composite.Bond(ilist=None)[source]
class hoobas.Composite.BondType(name=None, topodict=None, unitdict=None)[source]

A default class for bond types. Has topology properties of energy_constant (E/LL) and distance_constant(L).

class hoobas.Composite.CompositeObject(units=None, **kwargs)[source]

Class that handles topology information of building blocks of hoobas and keeps track of force-field constants

Args:
units: description of the current simulation units, as given by a SimulationUnits object. Defaults to default units
Attributes:

p_num: particle tag index of the CompositeObject used for building

beads: list of beads, managed by the BeadList class

bonds, angles, dihedrals, impropers: list of topologies, Managed by a TopologyList

subunits: Other CompositeObjects that make up the current one

superunit: CompositeObject where this is a subunit

att_list: list of sites where this has been attached

constraints: list of distance constraints in the simulation. Managed by a TopologyList b_types, a_types, d_types, i_types: list of force-fields related to the bonds. Managed by TopologyTypeList

Properties:
positions: returns a N x 3 numpy array from the BeadList class. The getter returns a reference so that it can be modified without a set, the setter will not change the underlying reference
get_subgraph(require=None, avoid=None)[source]

Builds a subgraph of the connectivity where nodes attributes match require and does not match avoid. This method requires the networkx package to work. Objects that are iterable are treated as OR logical requirements. For instance, require={‘beadtype’: [‘A’,’B’]} will make a subgraph of nodes with beadtypes ‘A’ or ‘B’, while avoid={‘beadtype’:[‘A’,’B’]} will avoid both ‘A’ and ‘B’

Parameters:
  • require (dict) – properties that are required to be part of the subgraph
  • avoid (dict) – properties that cause rejection of the node from the subgraph
Returns:

subgraph

Return type:

networkx.Graph

static import_mbuild(mbuild_object, units=None)[source]

Imports a muild object as a Hoobas composite object

Parameters:
  • mbuild_object (mbuild.compound) – mbuild object to import as Hoobas composite
  • units (SimulationUnits) – units of the mbuild object (default None)
Returns:

Hoobas representation of mbuild_object

Return type:

CompositeObject

static load(filepath)[source]

Returns the object contained in a file

Parameters:filepath (str) – path to file
Returns:object in file
Return type:CompositeObject
merge(other)[source]

merge another composite into this one without changing the other object

Parameters:other (CompositeObject) – object to merge into this one
Returns:None
override(filepath)[source]

Overrides the current object with one taken from a file

Parameters:filepath (str) – file to load
Returns:None
resolve_args(funct)[source]

Resolve arguments of a function by parsing arg names and gathering them from attributes of the composite object

Parameters:funct (callable) – function to resolve
Returns:argument list
Return type:dict
save(filepath)[source]

Save the current instance to a file

Parameters:filepath (str) – path to file
Returns:None
class hoobas.Composite.Constraint(ilist, distance=0.0)[source]
class hoobas.Composite.Dihedral(ilist=None)[source]
class hoobas.Composite.DihedralType(name='', topodict=None, unitdict=None)[source]

A default class for dihedral types. Has topology constants of energy_constant (E) and angle_constant (1)

class hoobas.Composite.ImproperType(name='', topodict=None, unitdict=None)[source]

A default class for improper types. Has topology constants of energy_constant (E) and angle_constant (1)

class hoobas.Composite.TopologyItem(idict=None)[source]

Defines a topology item, for instance, a bond

Args:
idict: optional dict initializer for the topologies

Note: Subclasses have well defined constructors. Bonds have 2 members and can be list initialized

>>> abond = Bond(['BondType', 0, 1])
>>> another_bond = Bond({'topology_tuple': (1, 2), 'topology_name': 'BondType'})
Attributes:

topology_tuple: indicates the associated particles in the topology. For a bond this would be a 2 membered tuple

topology_name: indicates the name associated with the topology. This is normally linked to a TopologyType name

class hoobas.Composite.TopologyList(topology_class)[source]

Defines a list of topologies of a given class of topologies.

A TopologyList keeps tracks of all bonded interactions of a given class (bond, angle, dihedral, …). It essentially works like a list: topologies can be retrieved by index with [] and iterated over.

Args:
topology_class: this defines the type of topology in the list (to avoid mixing bonds with angles)
Attributes:

topologies: list of topologies of class TopologyClass

topology_cls: class of topologies contained

topology_type_list: link to a list of types of topologies

Note: Adding a new topology (say a bond of type ‘A-A’) will check if ‘A-A’ is in topology_type_list and will add it as a default topology of its type (calling topology_cls constructor) if it is not present. The topology list supports augmented addition:

>>> BondList = TopologyList(Bond)
>>> ABond = Bond(['ABondName', 0, 1])
>>> BondList += ABond
>>> AnotherBondList = TopologyList(Bond)
>>> BondList += AnotherBondList
class hoobas.Composite.TopologyType(name='', topodict=None, unitdict=None)[source]

Base bonded force-field topology type which defines the base variables of every bonded type.

The class implements two dictionaries, one for topology constants (energy, distances, etc.) and one for the units of these constants. a name must also be given to the topology type to distinguish it from other types.

Args:

name: name of the type

topodict: dictionary which defines topology constants

unitdict: dictionary of units of the topology constants with matching keys of topodict

Examples:

This yields a bondname with name of ‘’ and keys ‘energy_constant’:0.0 (E/LL) and ‘distance_constant’: 0.0 (L)

>>> bond_type = BondType()

Topology types support initialization by list for harmonic bonds. For instance, this yields a bondtype named ‘BondTypeName’, with energy_constant of 1.0 (E/LL) and distance_constant of 5.0 (L)

>>> bond_type = BondType(['BondTypeName', 1.0, 5.0])

This yields a bondtype name ‘Anharmonic with ‘K2’ of 1.0 (E/LL), ‘K4’ of 1.0 (E/LLLL) and ‘D’ of 1.0 (L)

>>> bond_type = BondType('Anharmonic', {'K2':1.0, 'K4':1.0, 'D':1.0}, {'K2':'E/LL', 'K4':'E/LLLL', 'D':'L'})
Attributes:

typename: name of the TopologyType (‘BondTypeName’ or ‘Anharmonic’ in previous examples)

topology_constants: dictionary with numerical properties of the topology

topology_units: dictionary with unit transformation of the topology

class_name: class of potential associated with TopologyType, reserved for future implementation

static distance(obj1, obj2)[source]

Computes a topological distance between force-field parameters, defined as \(max_v(v_1 / v_2 - 1.0)\), where \(v\) iterates over force-field keys. If named keys of the force-field differ, the distance is set to \(\infty\)

Parameters:
Returns:

None

potential

Potential name associated with bonded parameter types.

Getter:returns the potential name
Setter:sets the potential name
Type:str
transform(length, energy, mass)[source]

Transforms the bonded force-field to match new unit types with multipliers given by length, energy and mass

Parameters:
  • length – new length
  • energy – new energy
  • mass – new mass
Returns:

None

class hoobas.Composite.TopologyTypeList(TopologyTypeClass)[source]

List of topology types (bonded force-field) objects used by CompositeObject

This class behaves similar to dictionary, topology types can be queried by key and can be iterated over. Additionally, the object supports augmented addition to join multiple lists of force-fields

Example:
>>> bond_type_list = TopologyTypeList(BondType)
>>> a_bond_type = BondType('BondType', [1.0, 1.0])
>>> bond_type_list += a_bond_type
>>> another_type_list = TopologyTypeList(BondType)
>>> bond_type_list += another_type_list

TopologyTypeLists are normally linked to a TopologyList to synchronize remapping and addition of force-fields. Types can be remapped with the remap method.

Example:
>>> bond_type_list = TopologyTypeList(BondType)
>>> bond_type_list += BondType('NoParams')  # a bond type with no parameters
>>> bond_type_list['NoParams'] = BondType('Params', [1.0, 1.0])  # remaps NoParams->Params and sets params
>>> bond_type_list.remap('Params', 'NoParams')  # remaps Params->NoParams
>>> bond_type_list['NoParams'] = BondType()  # removes coefficients from NoParams

Reduction in number of types can be achived by removing force-fields that are close in parameters, see the make_set method.

Args:
TopologyTypeClass: class of the held TopologyType

Links the topology list to a TopologyTypeList, this is normally done automatically by CompositeObject

Parameters:link (TopologyTypeList) – TypeList instance
Returns:None
make_set(tolerance=0.001, avoid=None)[source]

Makes a reduced set of topology types by merging types with distance less than the tolerance

Parameters:
  • tolerance (float) – maximum distance between merged types
  • avoid (list) – list of topology types to avoid merging
Returns:

remap(old, new)[source]

Remaps a topology name to another. If the new name already exists, the old type is destroyed and topologies of that type remapped to new.

Parameters:
  • old (str) – topology type to remap
  • new (str) – type to map to
Returns:

None

transform(length, energy, mass)[source]

Transforms the unit of all force fields

Parameters:
  • length – new length
  • energy – new energy
  • mass – new mass
Returns:

None

Unlinks the topology type list from the current topology list

Returns:None
hoobas.Composite.deferred(func)[source]

Decorator to defer function calls until the object is built

Parameters:func (callable) – decorated method
Returns:function wrapper
Return type:callable