Core Classes
The gmso.core module contains the concrete data structures used to represent a full
chemical topology. All classes are importable directly from the gmso namespace.
Topology
Topology is the central data structure in GMSO. It acts as the container
for all sites, connections, and forcefield parameters that together describe a molecular
system ready for simulation.
Summary
A topology. |
Reference
- class gmso.Topology(name='Topology', box=None)[source]
Bases:
objectA topology.
A topology represents a chemical structure wherein lie the collection of sites which together form a chemical structure containing connections (gmso.Bond, gmso.Angle and gmso.Dihedral (along with their associated types). A topology is the fundamental data structure in GMSO, from which we can gather various information about the chemical structure and apply a forcefield before converting the structure into a format familiar to various simulation engines.
- Parameters:
- combining_rule
The combining rule for the topology, can be either ‘lorentz’ or ‘geometric’
- Type:
str,[``’lorentz’, ``'geometric']
- n_connections
Number of connections in the topology (Bonds, Angles, Dihedrals, Impropers)
- Type:
- connections
A collection of bonds, angles, dihedrals, and impropers in the topology
- Type:
tupleofgmso.Connection objects
- connection_types
A collection of BondTypes, AngleTypes, DihedralTypes, and ImproperTypes in the topology
- Type:
tupleofgmso.Potential objects
- dihedral_types
A collection of DihedralTypes in the topology
- Type:
tupleofgmso.DihedralType objects
- improper_types
A collection of ImproperTypes in the topology
- Type:
tupleofgmso.ImproperType objects
- pairpotential_types
A collection of PairPotentialTypes in the topology
- Type:
tupleofgmso.PairPotentialType objects
- atom_type_expressions
A collection of all the expressions for the AtomTypes in topology
- Type:
listofgmso.AtomType.expression objects
- connection_type_expressions
A collection of all the expressions for the Potential objects in the topology that represent a connection type
- Type:
listofgmso.Potential.expression objects
- bond_type_expressions
A collection of all the expressions for the BondTypes in topology
- Type:
listofgmso.BondType.expression objects
- angle_type_expressions
A collection of all the expressions for the AngleTypes in topology
- Type:
listofgmso.AngleType.expression objects
- dihedral_type_expressions
A collection of all the expression for the DihedralTypes in the topology
- Type:
listofgmso.DihedralType.expression objects
- improper_type_expressions
A collection of all the expression for the ImproperTypes in the topology
- Type:
listofgmso.ImproperType.expression objects
- pairpotential_type_expressions
A collection of all the expression for the PairPotentialTypes in the topology
- Type:
listofgmso.PairPotentialType.expression objects
- property unit_system
Return the unyt system of the topology.
- property name
Return the name of the topology.
- property box
Return the Box of the topology.
- property typed
Check if the system is parametrized.
- property combining_rule
Return the combining rule for the topology.
- property scaling_factors
- property molecule_scaling_factors
- property positions
Return the positions of the sites in the topology.
- property n_sites
Return the number of sites in the topology.
- property virtual_sites
Return all virtual_sites in the topology.
- property n_virtual_sites
Return the number of virtual sites in the topology.
- property n_connections
Return the number of connections in the topology.
- property n_bonds
Return the number of bonds in the topology.
- property n_angles
Return the amount of angles in the topology.
- property n_dihedrals
Return the amount of dihedrals in the topology.
- property n_impropers
Return the number of impropers in the topology.
- property sites
Return all sites in the topology.
- property total_charge
Adds all the charges in the topologies
- property connections
Return all connections in topology.
- property bonds
Return all bonds in the topology.
- property angles
Return all angles in the topology.
- property dihedrals
Return all dihedrals in the topology.
- property impropers
Return all impropers in the topology.
- unique_site_labels(label_type='molecule', name_only=False)[source]
Return a list of all molecule/residue labels in the Topology.
- property atom_types
Return all atom_types in the topology.
Notes
This returns a TopologyPotentialView object which can be used as an iterator. By default, this will return a view with all the atom_types in the topology (if multiple sites point to the same atom_type, only a single reference is returned/iterated upon). Use, different filters(builtin or custom) to suit your needs. See examples below.
Examples
>>> from gmso.core.atom import Atom >>> from gmso.core.atom_type import AtomType >>> from gmso.core.topology import Topology >>> from gmso.core.views import PotentialFilters >>> top = Topology(name="my_top") >>> atom_type = AtomType(name="my_atom_type") >>> for j in range(100): ... atom = Atom(name=f"atom_{j+1}") ... atom.atom_type = atom_type ... top.add_site(atom) >>> len(top.atom_types) 1 >>> len(top.atom_types(filter_by=PotentialFilters.REPEAT_DUPLICATES)) 100 >>> len(top.atom_types(filter_by=PotentialFilters.UNIQUE_NAME_CLASS)) 1
See also
gmso.core.views.TopologyPotentialViewAn iterator/filter based view of Potentials in a gmso Topology.
gmso.core.views.PotentialFiltersBuiltin filters for viewing potentials in a Topology.
- Returns:
An iterator of the atom_types in the system filtered according to the filter function supplied.
- Return type:
gmso.core.views.TopologyPotentialView
- property connection_types
Return all connection_types in the topology.
Notes
This returns a TopologyPotentialView object which can be used as an iterator.
See also
gmso.core.views.TopologyPotentialViewAn iterator/filter based view of Potentials in a gmso Topology.
- property bond_types
Return all bond_types in the topology.
Notes
This returns a TopologyPotentialView object which can be used as an iterator.By default, this will return a view with all the bond_types in the topology (if multiple bonds point to the same bond_type, only a single reference is returned/iterated upon). Use, different filters(builtin or custom) to suit your needs. See examples below.
Examples
>>> from gmso.core.atom import Atom >>> from gmso.core.bond import Bond >>> from gmso.core.bond_type import BondType >>> from gmso.core.topology import Topology >>> from gmso.core.views import PotentialFilters >>> top = Topology(name="my_top") >>> for j in range(100): ... atom1 = Atom(name=f"atom_A_{j+1}") ... atom2 = Atom(name=f"atom_B_{j+1}") ... bond = Bond(connection_members=[atom1, atom2]) ... bond.bond_type = BondType(name=f"bond_type", member_types=('atom_A', 'atom_B')) ... conn = top.add_connection(bond) >>> len(top.bond_types) 100 >>> len(top.bond_types(filter_by=PotentialFilters.UNIQUE_ID)) 100 >>> len(top.bond_types(filter_by=PotentialFilters.UNIQUE_NAME_CLASS)) 1
See also
gmso.core.views.TopologyPotentialViewAn iterator/filter based view of Potentials in a gmso Topology.
gmso.core.views.PotentialFiltersBuiltin filters for viewing potentials in a Topology.
- Returns:
An iterator of the bond_types in the system filtered according to the filter function supplied.
- Return type:
gmso.core.views.TopologyPotentialView
- property angle_types
Return all angle_types in the topology.
Notes
This returns a TopologyPotentialView object which can be used as an iterator. By default, this will return a view with all the angle_types in the topology (if multiple angles point to the same angle_type, only a single reference is returned/iterated upon). Use, different filters(builtin or custom) to suit your needs. See examples below.
Examples
>>> from gmso.core.atom import Atom >>> from gmso.core.angle import Angle >>> from gmso.core.angle_type import AngleType >>> from gmso.core.topology import Topology >>> from gmso.core.views import PotentialFilters >>> for j in range(100): ... atom1 = Atom(name=f"atom_A_{j+1}") ... atom2 = Atom(name=f"atom_B_{j+1}") ... atom3 = Atom(name=f"atom_C_{j+1}") ... angle = Angle(connection_members=[atom1, atom2, atom3]) ... angle.angle_type = AngleType(name=f"angle_type", member_types=('atom_A', 'atom_B', 'atom_C')) ... conn = top.add_connection(angle) >>> len(top.angle_types) 100 >>> len(top.angle_types(filter_by=PotentialFilters.UNIQUE_ID)) 100 >>> len(top.angle_types(filter_by=PotentialFilters.UNIQUE_NAME_CLASS)) 1
See also
gmso.core.views.TopologyPotentialViewAn iterator/filter based view of Potentials in a gmso Topology.
gmso.core.views.PotentialFiltersBuiltin filters for viewing potentials in a Topology.
- Returns:
An iterator of the angle_types in the system filtered according to the filter function supplied.
- Return type:
gmso.core.views.TopologyPotentialView
- property dihedral_types
Return all dihedral_types in the topology.
Notes
This returns a TopologyPotentialView object which can be used as an iterator. By default, this will return a view with all the dihedral_types in the topology (if multiple dihedrals point to the same dihedral types, only a single reference is returned/iterated upon). Use, different filters(builtin or custom) to suit your needs. See examples below.
Examples
>>> from gmso.core.atom import Atom >>> from gmso.core.dihedral import Dihedral >>> from gmso.core.dihedral_type import DihedralType >>> from gmso.core.topology import Topology >>> from gmso.core.views import PotentialFilters >>> for j in range(100): ... atom1 = Atom(name=f"atom_A_{j+1}") ... atom2 = Atom(name=f"atom_B_{j+1}") ... atom3 = Atom(name=f"atom_C_{j+1}") ... atom4 = Atom(name=f"atom_D_{j+1}") ... dihedral = Dihedral(connection_members=[atom1, atom2, atom3, atom4]) ... dihedral.dihedral_type = DihedralType( ... name=f"dihedral_type", ... member_types=('atom_A', 'atom_B', 'atom_C', 'atom_D') ... ) ... conn = top.add_connection(dihedral) >>> len(top.dihedral_types) 100 >>> len(top.dihedral_types(filter_by=PotentialFilters.UNIQUE_ID)) 100 >>> len(top.dihedral_types(filter_by=PotentialFilters.UNIQUE_NAME_CLASS)) 1
See also
gmso.core.views.TopologyPotentialViewAn iterator/filter based view of Potentials in a gmso Topology.
gmso.core.views.PotentialFiltersBuiltin filters for viewing potentials in a Topology.
- Returns:
An iterator of the dihedral_types in the system filtered according to the filter function supplied.
- Return type:
gmso.core.views.TopologyPotentialView
- property improper_types
Return all improper_types in the topology.
Notes
This returns a TopologyPotentialView object which can be used as an iterator. By default, this will return a view with all the improper_types in the topology (if multiple impropers point to the same improper_type, only a single reference is returned/iterated upon). Use, different filters(builtin or custom) to suit your needs. See examples below.
Examples
>>> from gmso.core.atom import Atom >>> from gmso.core.improper import Improper >>> from gmso.core.improper_type import ImproperType >>> from gmso.core.topology import Topology >>> from gmso.core.views import PotentialFilters >>> for j in range(100): ... atom1 = Atom(name=f"atom_A_{j+1}") ... atom2 = Atom(name=f"atom_B_{j+1}") ... atom3 = Atom(name=f"atom_C_{j+1}") ... atom4 = Atom(name=f"atom_D_{j+1}") ... improper = Improper(connection_members=[atom1, atom2, atom3, atom4]) ... improper.improper_type = ImproperType( ... name=f"dihedral_type", ... member_types=('atom_A', 'atom_B', 'atom_C', 'atom_D') ... ) ... conn = top.add_connection(improper) >>> len(top.improper_types) 100 >>> len(top.improper_types(filter_by=PotentialFilters.UNIQUE_ID)) 100 >>> len(top.improper_types(filter_by=PotentialFilters.UNIQUE_NAME_CLASS)) 1
See also
gmso.core.views.TopologyPotentialViewAn iterator/filter based view of Potentials in a gmso Topology.
gmso.core.views.PotentialFiltersBuiltin filters for viewing potentials in a Topology.
- Returns:
An iterator of the dihedral_types in the system filtered according to the filter function supplied.
- Return type:
gmso.core.views.TopologyPotentialView
- property pairpotential_types
- property atom_type_expressions
Return all atom_type expressions in the topology.
- property connection_type_expressions
Return all connection_type expressions in the topology.
- property bond_type_expressions
Return all bond_type expressions in the topology.
- property angle_type_expressions
Return all angle_type expressions in the topology.
- property dihedral_type_expressions
Return all dihedral_type expressions in the topology.
- property improper_type_expressions
Return all improper_type expressions in the topology.
- property pairpotential_type_expressions
- get_lj_scale(*, molecule_id=None, interaction=None)[source]
Return the selected lj_scales defined for this topology.
- set_lj_scale(value, *, molecule_id=None, interaction=None)[source]
Set the correct lj_scaling factors for this topology.
- get_scaling_factors(*, molecule_id=None)[source]
Get the scaling factor of this topology or for a particular molecule
- remove_site(site)[source]
Remove a site from the topology.
- Parameters:
site (
gmso.core.Site) – The site to be removed.
Notes
When a site is removed, any connections that site belonged to are also removed.
See also
gmso.core.topology.Topology.iter_connections_by_siteThe method that shows all connections belonging to a specific site
- remove_connection(connection)[source]
Remove a connection from the topology.
- Parameters:
connection (
gmso.abc.abstract_conneciton.Connection) – The connection to be removed from the topology
Notes
The sites that belong to this connection are not removed from the topology.
- set_scaling_factors(lj, electrostatics, *, molecule_id=None)[source]
Set both lj and electrostatics scaling factors.
- get_electrostatics_scale(*, molecule_id=None, interaction=None)[source]
Return the selected electrostatics_scale defined for this topology.
- Parameters:
- Raises:
GMSOError – If the specified parameters can’t return a scaling factor
- set_electrostatics_scale(value, *, molecule_id=None, interaction=None)[source]
Set the correct lj_scaling factors for this topology.
- Parameters:
value (
float,numpy.ndarray,list, ortupleoffloats) – The value to set for this scalemolecule_id (
str, defaultNone) – The molecule id that this scaling factor applies to, if None this will return the Topology’s global scaling factorsinteraction (
str,oneof{'12', '13', '14'}, defaultNone) – The interaction for which to return the scaling factor for, if None a 3 tuple
- Raises:
GMSOError – If the specified parameters can’t return a scaling factor
- add_site(site, update_types=False)[source]
Add a site to the topology.
This method will add a site to the existing topology, since sites are stored in an indexed set, adding redundant site will have no effect. If the update_types parameter is set to true (default behavior), this method will also check if there is an gmso.AtomType associated with the site and it to the topology’s AtomTypes collection.
- Parameters:
site (
gmso.core.Site) – Site to be added to this topologyupdate_types (
(bool), defaultTrue) – If true, add this site’s atom type to the topology’s set of AtomTypes
- add_connection(connection, update_types=False)[source]
Add a gmso.Connection object to the topology.
This method will add a gmso.Connection object to the topology, it can be used to generically include any Connection object i.e. Bond or Angle or Dihedral to the topology. According to the type of object added, the equivalent collection in the topology is updated. For example- If you add a Bond, this method will update topology.connections and topology.bonds object. Additionally, if update_types is True (default behavior), it will also update any Potential objects associated with the connection.
- Parameters:
connection (
oneofgmso.Connection,gmso.Bond,gmso.Angle,gmso.Dihedral, orgmso.Improper object)update_types (
bool, defaultTrue) – If True also add any Potential object associated with connection to the topology.
- Returns:
The Connection object or equivalent Connection object that is in the topology
- Return type:
gmso.Connection
- remove_pairpotentialtype(pair_of_types)[source]
Remove the custom pairwise potential between two AtomTypes/Atomclasses
- Parameters:
pair_of_types (
list-likeofstrs) – The pair (or set) of names or atomclasses of gmso.AtomTypes of which the custom pairwise potential should be removed
- is_fully_typed(group='topology', updated=False)[source]
Check if the topology or a specifc group of objects that make up the topology are fully typed
- Parameters:
updated (
bool, optional, defaultFalse) – If False, will update the atom type and connection type list of the Topology before the checking step.group (
str, optional, default'topology') – Specific objects to be checked. Options include: ‘topology’ : check for status of all the topology constituents ‘sites’ : check for status of all topology.sites ‘bonds’ : check for status of all topology.bonds ‘angles’ : check for status of all topology.angles ‘dihedrals’ : check for status of all topology.dihedrals ‘impropers’ : check for status of all topology.impropers
- Returns:
Status of the check
- Return type:
Notes
self._type is set to True as long as the Topology is at least partially typed.
- get_untyped(group)[source]
Get the untyped (non-parametrized) objects of the Topology.
- Parameters:
group (
{'sites', 'bonds', 'angles', 'dihedrals', 'impropers', 'topology'}) – The group of objects to be checked. The ‘topology’ option will return all untyped object of the topology.- Returns:
untyped – Dictionary of all untyped object, key of the dictionary corresponds to object group names define above.
- Return type:
- update_angle_types()[source]
Use gmso.Topology.update_connection_types to update AngleTypes in the topology.
This method is an alias for gmso.Topology.update_connection_types.
See also
gmso.Topology.update_connection_typesUpdate the connection types based on the connection collection in the topology.
- update_bond_types()[source]
Use gmso.Topology.update_connection_types to update BondTypes in the topology.
This method is an alias for gmso.Topology.update_connection_types.
See also
gmso.Topology.update_connection_typesUpdate the connection types based on the connection collection in the topology.
- update_dihedral_types()[source]
Use gmso.Topology.update_connection_types to update DihedralTypes in the topology.
This method is an alias for gmso.Topology.update_connection_types.
See also
gmso.Topology.update_connection_typesUpdate the connection types based on the connection collection in the topology.
- update_improper_types()[source]
Use gmso.Topology.update_connection_types to update ImproperTypes in the topology.
This method is an alias for gmso.Topology.update_connection_types.
See also
gmso.Topology.update_connection_typesUpdate the connection types based on the connection collection in the topology.
- get_index(member)[source]
Get index of a member in the topology.
- Parameters:
member (
gmso Topology objects) – The member to for which to return index for. member can be of type gmso.Site, gmso.Bond, gmso.Angle, gmso.Dihedral, gmso.Improper, gmso.AtomType, gmso.BondType, gmso.AngleType, gmso.DihedralType or gmso.ImproperType.- Returns:
The index of the member in the topology’s collection objects
- Return type:
- write_forcefield(filename, overwrite=False)[source]
Save an xml file for all parameters found in the topology.
- Parameters:
Notes
This method can be used to save a small, trimmed down forcefield from a larger forcefield (e.g. oplsaa). This is useful for editing, saving, and sharing forcefield parameters.
- Raises:
GMSOError – If the topology is untyped
- to_dataframe(parameter='sites', site_attrs=None, unyts_bool=True)[source]
Return a pandas dataframe object for the sites in a topology
- Parameters:
parameter (
str, default'sites') – A string determining what aspects of the gmso topology will be reported. Options are: ‘sites’, ‘bonds’, ‘angles’, ‘dihedrals’, and ‘impropers’. Defaults to ‘sites’.site_attrs (
listofstr, defaultNone) – List of strings that are attributes of the topology site and can be included as entries in the pandas dataframe. Examples of these can be found by printing topology.sites[0].__dict__. See https://gmso.mosdef.org/en/stable/data_structures.html#gmso.Atom for additional information on labeling.unyts_bool (
bool, defaultTrue) – Determine if numerical values are saved as unyt quantities or floats. See https://unyt.readthedocs.io/en/stable/usage.html for more information about manipulating unyt quantities. Default is True.
- Returns:
A pandas.Dataframe object, see https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html for further information.
- Return type:
Pandas Dataframe
Examples
Return a dataframe with site names and charges:
>>> topology.to_dataframe(parameter='sites', site_attrs=['charge'])
Return a dataframe listing the sites and parameters for each dihedral:
>>> topology.to_dataframe(parameter='dihedrals', site_attrs=['positions'])
Notes
A dataframe is easily manipulated. To round a column named
labelto two decimal places:>>> df['label'] = df['label'].round(2)
To rename a column
Atom0tonewname:>>> df.rename(columns={'Atom0': 'newname'})
See https://pandas.pydata.org/pandas-docs/stable/getting_started/intro_tutorials/index.html for further information.
- get_forcefield()[source]
Get an instance of gmso.ForceField out of this topology
- Raises:
GMSOError – If the topology is untyped
- iter_sites_and_virtual_sites(key, value)[source]
Iterate through this topology’s sites based on certain attribute and their values.
- Parameters:
key (
str) – The attribute of the site to look forvalue – The value that the given attribute should be equal to
- Yields:
gmso.abc.abstract_site.Site– The site where getattr(site, key) == value
- iter_sites(key, value)[source]
Iterate through this topology’s sites based on certain attribute and their values.
- Parameters:
key (
str) – The attribute of the site to look forvalue – The value that the given attribute should be equal to
- Yields:
gmso.abc.abstract_site.Site– The site where getattr(site, key) == value
- iter_sites_by_residue(residue_tag)[source]
Iterate through this topology’s sites which contain this specific residue name.
See also
gmso.core.topology.Topology.iter_sitesThe method to iterate over Topology’s sites
- iter_sites_by_molecule(molecule_tag)[source]
Iterate through this topology’s sites which contain this specific molecule name.
See also
gmso.core.topology.Topology.iter_sitesThe method to iterate over Topology’s sites
- iter_connections_by_site(site, connections=None)[source]
Iterate through this topology’s connections which contain this specific site.
- Parameters:
- Yields:
gmso.abc.abstract_conneciton.Connection– Connection where site is in Connection.connection_members
- create_subtop(label_type, label)[source]
Create a new Topology object from a molecule or graup of the current Topology.
- Parameters:
label_type (
str) – Category of the label (“group” or “molecule”)label (
str (group)ortuple (molecule)) – The label of molecule or group that need to be cloned.
- Return type:
- save(filename, overwrite=False, **kwargs)[source]
Save the topology to a file.
- Parameters:
filename (
str,pathlib.Path) – The file to save the topology asoverwrite (
bool, defaultTrue) – If True, overwrite the existing file if it exists**kwargs – The arguments to specific file savers listed below(as extensions): * json: types, update, indent * gro: precision * lammps/lammpsdata: atom_style
- convert_potential_styles(expressionMap={})[source]
Convert from one parameter form to another.
- Parameters:
expressionMap (
dict, default{}) – Map where the keys represent the current potential type and the corresponding values represent the desired potential type. The desired potential style can be either a string with the corresponding name, or a gmso.utils.expression.PotentialExpression type.
Examples
# Convert from RB torsions to OPLS torsions top.convert_potential_styles({“dihedrals”: “OPLSTorsionPotential”}) # TODO: convert_potential_styles with PotentialExpression
- convert_unit_styles(unitsystem, exp_unitsDict)[source]
Convert from one set of base units to another.
- Parameters:
unitsystem (
unyt.UnitSystem) – set of base units to use for all expressions of the topology in unyt package <https://unyt.readthedocs.io/en/stable/>_exp_unitsDict (
dict) – keys with topology attributes that should be converted and values with dictionary of parameter: expected_dimension
Examples
>>> top.convert_unit_styles( ... u.UnitSystem("lammps_real", "Å", "amu", "fs", "K", "rad"), ... {"bond": {"k": "energy/length**2", "r_eq": "length"}}, ... )
Sites
Sites are the fundamental interaction points in a topology. GMSO ships two concrete site
types: Atom for element-bearing particles, and
VirtualSite for massless interaction centres (e.g., TIP4P water models).
An atom represents a single element association in a topology. |
|
A generalized virtual site class in GMSO. |
Atom
- class gmso.Atom(**data)[source]
Bases:
SiteAn atom represents a single element association in a topology.
Atoms are the representation of an element within gmso that describes any general atom in a molecular simulation. Atoms also contain information that are unique to elements vs other types of interaction sites in molecular simulations. For example, charge, mass, and periodic table information.
Notes
Atoms have all the attributes inherited from the base Site class, The order of precedence when attaining properties charge and mass is:
atom.charge > atom.atom_type.charge
atom.mass > atom.atom_type.mass
Examples
>>> from gmso.core.atom import Atom >>> atom1 = Atom(name='lithium')
See also
gmso.abc.AbstractSiteAn Abstract Base class for implementing site objects in GMSO. The class Atom bases from the gmso.abc.abstract site class
- charge_: unyt_quantity | float | None
- mass_: unyt_quantity | float | None
- property charge: unyt_quantity | None
Return the charge of the atom.
- property mass: unyt_quantity | None
Return the mass of the atom.
- property restraint
Return the restraint of this atom.
VirtualSite
- class gmso.VirtualSite(**data)[source]
Bases:
SiteA generalized virtual site class in GMSO.
Virtual sites are massless particles that represent off-atom charge/interaction sites, lone pairs, or other non-physical sites.
- charge
The charge of the virtual site in elementary charge units. Will prioritize self.virtual_type.charge.
- Type:
u.unyt_array
- parent_sites
The real constituent sites that define the virtual site’s position.
- Type:
List[Site]
- virtual_type
The type information, including parameters for virtual_position and virtual_potential, used to define the virtual site’s interactions and positions
- charge_: unyt_quantity
- virtual_type_: VirtualType | None
- property parent_sites: List[Site]
Reminder that the order of sites is fixed, such that site index 1 corresponds to ri in the self.virtual_type.virtual_position expression.
- position()[source]
On the fly position evaluation from virtual_type.virtual_position and parent_sites.
- Return type:
- property virtual_type
Return the virtual site type if the virtual site is parametrized.
- property charge: unyt_quantity | None
Return the charge of the virtual site.
Connections
Connections encode the covalent topology of a system. They are built from ordered sequences
of Atom members and an optional connection type that carries the forcefield
parameters.
Bonded connections must be defined, either in the file used to create the gmso.Topology or
in the conversion from another object into a gmso.Topology. If the bond connections are
correctly identified, you can use gmso.utils.connectivity.identify_connections() to infer
and populate the rest of the connections (i.e., angles, dihedrals and improper dihedrals.)
A 2-partner connection between sites. |
|
A 3-partner connection between Atoms. |
|
A 4-partner connection between sites. |
|
A 4-partner connection between sites. |
Bond
- class gmso.Bond(**data)[source]
Bases:
ConnectionA 2-partner connection between sites.
This is a subclass of the gmso.abc.Connection superclass. This class has strictly 2 members in its connection_members. The connection_type in this class corresponds to gmso.BondType.
Notes
Inherits some methods from Connection: __eq__, __repr__, _validate methods.
Additional _validate methods are presented.
- property bond_type
Return parameters of the potential type.
- property connection_type
Return parameters of the potential type.
- property restraint
Return the restraint of this bond.
- property bond_order
Return the bond_order of this bond.
Angle
- class gmso.Angle(**data)[source]
Bases:
ConnectionA 3-partner connection between Atoms.
This is a subclass of the gmso.Connection superclass. This class has strictly 3 members in its connection members. The connection_type in this class corresponds to gmso.AngleType.
Notes
Inherits some methods from Connection: __eq__, __repr__, _validate methods
Additional _validate methods are presented.
self.connectivity is the associated indices that defines the way connection_members are bonded to match self.bonds.
- property angle_type
Return the angle type if the angle is parametrized.
- property connection_type
Return the angle type if the angle is parametrized.
- property restraint
Return the restraint of this angle.
- property bonds
Return a tuple of gmso.core.Bond objects that correspond to this angle.
- property bonds_orders
Return the bond_order strings of this angle.
Dihedral
- class gmso.Dihedral(**data)[source]
Bases:
ConnectionA 4-partner connection between sites.
This is a subclass of the gmso.Connection superclass. This class has strictly 4 members in its connection_members. The connection_type in this class corresponds to gmso.DihedralType. The connectivity of a dihedral is: m1–m2–m3–m4
where m1, m2, m3, and m4 are connection members 1-4, respectively.
Notes
Inherits some methods from Connection: __eq__, __repr__, _validate methods
Additional _validate methods are presented.
- dihedral_type_: DihedralType | None
- property dihedral_type
- property connection_type
- property restraint
Return the restraint of this dihedral.
- property bonds
Return the bonds that makeup this dihedral.
Connectivity is ((0,1), (1,2), (2,3))
- property bonds_orders
Return the bond_order strings of this dihedral.
Improper
- class gmso.Improper(**data)[source]
Bases:
ConnectionA 4-partner connection between sites.
This is a subclass of the gmso.Connection superclass. This class has strictly 4 members in its connection_members. The connection_type in this class corresponds to gmso.ImproperType The connectivity of an improper is:
m2
m3 - m1 - m4
where m1, m2, m3, and m4 are connection members 1-4, respectively.
Notes
Inherits some methods from Connection: __eq__, __repr__, _validate methods
Additional _validate methods are presented.
- improper_type_: ImproperType | None
- property improper_type
Return Potential object for this connection if it exists.
- property connection_type
Return Potential object for this connection if it exists.
- property bonds
Return the bonds that makeup this Improper.
Connectivity is ((0,1), (0,2), (0,3))
- property bonds_orders
Return the bond_order strings of this improper.
Potential Types
Potential types carry the functional form and parameters for a given interaction class.
They attach to the corresponding connection (or site) via the *_type attributes.
A description of non-bonded interactions between sites. |
|
A descripton of the interaction between 2 bonded partners. |
|
A descripton of the interaction between 3 bonded partners. |
|
A descripton of the interaction between 4 bonded partners. |
|
A description of the interaction between 4 bonded partners. |
|
A description of custom pairwise potential between 2 AtomTypes that does not follow combination rule. |
|
A generalized virtual site type class in GMSO. |
AtomType
- class gmso.AtomType(name='AtomType', mass=unyt_quantity(0., 'g/mol'), charge=unyt_quantity(0., 'C'), expression=None, parameters=None, potential_expression=None, independent_variables=None, atomclass='', doi='', overrides=None, definition='', description='', tags=None)[source]
Bases:
ParametricPotentialA description of non-bonded interactions between sites.
This is a subclass of the gmso.core.Potential superclass.
AtomType represents an atom type and includes the functional form describing its interactions and, optionally, other properties such as mass and charge. This class inhereits from Potential, which stores the non-bonded interaction between atoms or sites. The functional form of the potential is stored as a sympy expression and the parameters, with units, are stored explicitly.
- mass_: unyt_array | None
- charge_: unyt_array | None
- property charge
Return the charge of the atom_type.
- property mass
Return the mass of the atom_type.
- property atomclass
Return the atomclass of the atom_type.
- property doi
Return the doi of the atom_type.
- property overrides
Return the overrides of the atom_type.
- property description
Return the description of the atom_type.
- property definition
Return the SMARTS string of the atom_type.
BondType
- class gmso.BondType(name='BondType', expression=None, parameters=None, independent_variables=None, potential_expression=None, member_types=None, member_classes=None, identifier=None, tags=None)[source]
Bases:
ParametricPotentialA descripton of the interaction between 2 bonded partners.
This is a subclass of the gmso.core.Potential superclass.
BondType represents a bond type and includes the functional form describing its interactions. The functional form of the potential is stored as a sympy expression and the parameters, with units, are stored explicitly. The AtomTypes that are used to define the bond type are stored as member_types.
Notes
Inherits many functions from gmso.ParametricPotential:
__eq__,_validatefunctions.- property member_types
Return the members involved in this bondtype.
- property member_classes
- property identifier
AngleType
- class gmso.AngleType(name='AngleType', expression=None, parameters=None, independent_variables=None, potential_expression=None, member_types=None, member_classes=None, identifier=None, tags=None)[source]
Bases:
ParametricPotentialA descripton of the interaction between 3 bonded partners.
This is a subclass of the gmso.core.Potential superclass.
AngleType represents an angle type and includes the functional form describing its interactions. The functional form of the potential is stored as a sympy expression and the parameters, with units, are stored explicitly. The AtomTypes that are used to define the angle type are stored as member_types.
Notes
Inherits many functions from gmso.ParametricPotential:
__eq__,_validatefunctions.- property member_types
- property member_classes
- property identifier
DihedralType
- class gmso.DihedralType(name='DihedralType', expression=None, parameters=None, independent_variables=None, potential_expression=None, member_types=None, member_classes=None, identifier=None, tags=None)[source]
Bases:
ParametricPotentialA descripton of the interaction between 4 bonded partners.
This is a subclass of the gmso.core.Potential superclass.
DihedralType represents a dihedral type and includes the functional form describing its interactions. The functional form of the potential is stored as a sympy expression and the parameters, with units, are stored explicitly. The AtomTypes that are used to define the dihedral type are stored as member_types.
The connectivity of a dihedral is:
m1–m2–m3–m4
where m1, m2, m3, and m4 are connection members 1-4, respectively.
Notes
Inherits many functions from gmso.ParametricPotential:
__eq__,_validatefunctions.- property member_types
- property member_classes
- property identifier
ImproperType
- class gmso.ImproperType(name='ImproperType', expression=None, parameters=None, independent_variables=None, potential_expression=None, member_types=None, member_classes=None, identifier=None, tags=None)[source]
Bases:
ParametricPotentialA description of the interaction between 4 bonded partners.
This is a subclass of the gmso.core.Potential superclass.
ImproperType represents a improper type and includes the functional form describing its interactions. The functional form of the potential is stored as a sympy expression and the parameters, with units, are stored explicitly. The AtomTypes that are used to define the improper type are stored as member_types. The connectivity of an improper is:
m2
m3 - m1 - m4
where m1, m2, m3, and m4 are connection members 1-4, respectively.
Notes
Inherits many functions from gmso.ParametricPotential:
__eq__,_validatefunctions.- property member_types
Return member information for this ImproperType.
- property member_classes
- property identifier
PairPotentialType
- class gmso.PairPotentialType(name='PairPotentialType', expression=None, parameters=None, independent_variables=None, potential_expression=None, member_types=None, identifier=None, tags=None)[source]
Bases:
ParametricPotentialA description of custom pairwise potential between 2 AtomTypes that does not follow combination rule.
This is a subclass of the gmso.core.ParametricPotential superclass.
PairPotentialType represents a type of pairwise potential between two Atomtypes that does not follow a specific combination rule, and includes the functional form describing its interactions. The functional form of the potential is stored as a sympy expression and the parameters, with units, are stored explicitly. The AtomTypes that are used to define the dihedral type are stored as member_types.
Notes
- Inherits many functions from gmso.ParametricPotential:
__eq__, _validate functions
- property member_types
- property identifier
VirtualType
- class gmso.VirtualType(**data)[source]
Bases:
GMSOBaseA generalized virtual site type class in GMSO.
Virtual sites are massless particles that represent off-atom interaction/charge sites, lone pairs, or other non-physical sites.
- name
A generalized name for the type of the virtual site. See https://manual.gromacs.org/current/reference-manual/functions/interaction-methods.html#id3 for some Gromacs examples.
- Type:
- member_types_
The atom types of the constituent atoms that define the virtual site’s position.
- Type:
List[Str]
- member_classes_
The atom classes of the constituent atoms that define the virtual site’s position.
- Type:
List[Str]
- charge
The charge of the virtual site in elementary charge units.
- Type:
u.unyt_array
- virtual_potential
The ParametricPotential that takes the specific parent_atoms and is used to generate the specific virtual site position.
- Type:
gmso.core.virtual_type.VirtualPositionType
- virtual_position
The ParametricPotential that is used to store the nonbonded interactions of the virtual site type.
- Type:
gmso.core.virtual_type.VirtualPotentialType
- charge_: unyt_array | None
- property virtual_position: VirtualPositionType
- property virtual_potential: VirtualPotentialType
- property member_types
- property member_classes
- property identifier
- property charge
- property doi
Return the doi of the virtual_type.
- classmethod validate_charge(charge)[source]
Check to see that a charge is a unyt array of the right dimension.
ForceField
ForceField parses and stores the potential types and parameters defined in a
forcefield XML file (Foyer/OpenMM format). It is the primary input to
gmso.parameterization.apply().
A generic implementation of the forcefield class. |
- class gmso.ForceField(xml_loc=None, strict=True, greedy=True, backend='forcefield-utilities')[source]
Bases:
objectA generic implementation of the forcefield class.
The ForceField class is one of the core data structures in gmso, which is used to hold a collection of gmso.core.Potential subclass objects along with some metadata to represent a forcefield. The forcefield object can be applied to any gmso.Topology which has effects on its Sites, Bonds, Angles and Dihedrals.
- Parameters:
xml_loc (
str) – Path to the forcefield xml. The forcefield xml can be either in Foyer or GMSO style.strict (
bool, defaultTrue) – If true, perform a strict validation of the forcefield XML filegreedy (
bool, defaultTrue) – If True, when using strict mode, fail on the first error/mismatchbackend (
str, default"forcefield-utilities") – Can be “gmso” or “forcefield-utilities”. This will define the methods to load the forcefield.
See also
gmso.ForceField.from_xmlA class method to create forcefield object from XML files
gmso.utils.ff_utils.validateFunction to validate the gmso XML file
- property non_element_types
Get the non-element types in the ForceField.
- property atom_class_groups
Return a dictionary of atomClasses in the Forcefield.
- group_atom_types_by_expression()[source]
Return all AtomTypes in this ForceField with grouped by expression.
See also
_group_by_expressionGroups a dictionary of gmso.ParametricPotentials by their expression
- Returns:
A dictionary where the key, value -> expression, list of atom_types with that expression
- Return type:
- group_bond_types_by_expression()[source]
Return all BondTypes in this ForceField with grouped by expression.
See also
_group_by_expressionGroups a dictionary of gmso.ParametricPotentials by their expression
- Returns:
A dictionary where the key, value -> expression, list of BondTypes with that expression
- Return type:
- group_angle_types_by_expression()[source]
Return all AngleTypes in this ForceField with grouped by expression.
See also
_group_by_expressionGroups a dictionary of gmso.ParametricPotentials by their expression
- Returns:
A dictionary where the key, value -> expression, list of AngleTypes with that expression
- Return type:
- group_dihedral_types_by_expression()[source]
Return all DihedralTypes in this ForceField with grouped by expression.
See also
_group_by_expressionGroups a dictionary of gmso.ParametricPotentials by their expression
- Returns:
A dictionary where the key, value -> expression, list of DihedralTypes with that expression
- Return type:
- group_improper_types_by_expression()[source]
Return all ImproperTypes in this ForceField with grouped by expression.
See also
_group_by_expressionGroups a dictionary of gmso.ParametricPotentials by their expression
- Returns:
A dictionary where the key, value -> expression, list of ImproperTypes with that expression
- Return type:
- group_pairpotential_types_by_expression()[source]
Return all PairPotentialTypes in this ForceField with grouped by expression
See also
_group_by_expressionGroups a dictionary of gmso.ParametricPotentials by their expression
- Returns:
A dictionary where the key, value -> expression, list of PairPotentialTypes with that expression
- Return type:
- group_virtual_types_by_expression()[source]
Return all VirtualTypes in this ForceField with grouped by expression.
See also
_group_by_expressionGroups a dictionary of gmso.ParametricPotentials by their expression
- Returns:
A dictionary where the key, value -> expression, list of VirtualTypes with that expression
- Return type:
- get_potential(group, key, exact_match=False)[source]
Return a specific potential by key in this ForceField.
- Parameters:
group (
{'atom_type', 'bond_type', 'angle_type', 'dihedral_type', 'improper_type', 'virtual_type'}) – The potential group to perform this search onkey (
str (for atom type)orlistofstr (for connection types)) – The key to lookup for this potential groupexact_match (
bool, defaultFalse) – If False, use wildcard matching to check for valid matches in the forcefield.
- Returns:
The parametric potential requested
- Return type:
gmso.ParametricPotential- Raises:
MissingPotentialError – When the potential specified by key is not found in the ForceField potential group group
- get_parameters(group, key, exact_match=False, copy=False)[source]
Return parameters for a specific potential by key in this ForceField.
This function uses the get_potential function to get Parameters
See also
gmso.ForceField.get_potentialGet specific potential/parameters from a forcefield potential group by key
- to_xml(filename, overwrite=False, backend='gmso')[source]
Get an lxml ElementTree representation of this ForceField
- Parameters:
- classmethod from_xml(xmls_or_etrees, strict=True, greedy=True)[source]
Create a gmso.Forcefield object from XML File(s).
This class method creates a ForceField object from the reference XML file. This method takes in a single or collection of XML files with information about gmso.AtomTypes, gmso.BondTypes, gmso.AngleTypes , gmso.PairPotentialTypes and gmso.DihedralTypes to create the ForceField object.
- Parameters:
xmls_or_etrees (
Union[str,Iterable[str],etree._ElementTree,Iterable[etree._ElementTree]]) – The forcefield XML locations or XML Element Treesstrict (
bool, defaultTrue) – If true, perform a strict validation of the forcefield XML filegreedy (
bool, defaultTrue) – If True, when using strict mode, fail on the first error/mismatch
- Returns:
forcefield – A gmso.Forcefield object with a collection of Potential objects created using the information in the XML file
- Return type:
Box
Box stores periodic boundary information for a simulation cell.
- class gmso.Box(lengths, angles=None)[source]
Bases:
objectA box that bounds a Topology.
The Box data structure contains the relevant information to fully describe a simulation box in three dimensions, including lengths, angles, and vectors
It is based on the Bravais lattice concept. A 3-dimensional prism can be fully described with 6 parameters, the lengths of the 3 edges of the prism (a,`b`,`c`); and the 3 interplanar angles that describe the tilt of the prism edges (alpha, beta, gamma). For example, the Bravais parameters where a=b=c, and alpha=beta=gamma=90 define a cubic prism (cube).
- Parameters:
lengths (
array-like,shape(3,),dtype=float) – Lengths of the box [a, b, c]. Units are assumed to be in nm; if passed in as a unyt_array it will be converted to nm; if passed in as floats, nm is assumed.angles (
array-like, optional,shape(3,),dtype=float) – Interplanar angles, [alpha, beta, gamma], that describe the box shape. Units are assumed to be in degrees; if passed in as a unyt_array it will be converted to degrees; if passed in as floats, degrees are assumed.
- a, b, c
Lengths of the box.
- Type:
- alpha, beta, gamma
Interplanar angles fully describing the Box.
- Type:
- property lengths
Return edge lengths of the box.
- property angles
Return angles of the box.
Element
Element provides periodic-table data (mass, symbol, atomic number, etc.).
- class gmso.Element(**data)[source]
Bases:
GMSOBaseChemical element object
Template to create a chemical element. Properties of the element instance are immutable. All known elements are pre-built and stored internally.
- mass: unyt_quantity