TypeParameter¶
- class hoomd.data.TypeParameter(name, type_kind, param_dict)¶
Store parameters by type or type pair.
Implements the
collections.abc.MutableMapping
interface (excluding__delitem__
).Many operations in HOOMD-blue utilize parameters that depend on the type or pairs of types. For example, the Langevin drag coefficient (
hoomd.md.methods.Langevin.gamma
) are set by particle type and Lennard-Jones pair potential parameters (hoomd.md.pair.LJ.params
) are set by pairs of particle types.TypeParameter
holds the values of these type (or type pair) dependent parameters. It also provides convenience methods for setting defaults and multiple parameters on one line.Important
Parameters for all types (or unordered pairs of types) in the simulation state must be defined prior to calling
Simulation.run()
.Note
TypeParameter
removes types (or type pairs) not present in the simulation state after its operation is added to the simulation and the simulation has been run for 0 or more steps.The examples below use
hoomd.md.methods.Langevin
andhoomd.md.pair.LJ
to demonstrate.lj = hoomd.md.pair.LJ(nlist=hoomd.md.nlist.Cell(buffer=0.4)) langevin = hoomd.md.methods.Langevin(filter=hoomd.filter.All(), kT=1.0)
- __delitem__(key)¶
__delitem__ is not available for
TypeParameter
objects.
- __eq__(other)¶
Test for equality.
langevin.gamma == lj.params
- __getattr__(attr)¶
Access parameter attributes.
- __getitem__(key)¶
Access parameters by key or keys.
Examples:
gamma_A = langevin.gamma["A"]
lj_epsilon_AB = lj.params[("A", "B")]["epsilon"]
Multiple keys
When
key
denotes multiple pairs (see__setitem__
),__getitem__
returns multiple items in a dictionary:gammas = langevin.gamma[["A", "B"]]
is equivalent to:
gammas = {key: langevin.gamma[key] for key in ["A", "B"]}
- __getstate__()¶
Prepare data for pickling.
- __iter__()¶
Iterate over the keys in the mapping.
Example:
for type_pair in lj.params: pass
- __len__()¶
Get the number of type parameters in the mapping.
Example:
n_type_pairs = len(lj.params)
- __setitem__(key, value)¶
Set parameters for a given type (or type pair).
Examples:
Index types by name:
langevin.gamma["A"] = 2.0
Set parameters for multiple types:
langevin.gamma[["B", "C"]] = 3.0
Set type pair parameters with a tuple of names:
lj.params[("A", "A")] = dict(epsilon=1.5, sigma=2.0)
Set parameters for multiple pairs (e.g. (‘A’, ‘B’) and (‘A’, ‘C’)):
lj.params[("A", ["B", "C"])] = dict(epsilon=0, sigma=0)
Set parameters for multiple pairs (e.g. (‘B’, ‘B’), (‘B’, ‘C’), (‘C’, ‘B’), and (‘C’, ‘C’)):
lj.params[(["B", "C"], ["B", "C"])] = dict(epsilon=1, sigma=1)
Note
Setting the value for (a,b) automatically sets the symmetric (b,a) parameter to the same value.
- __setstate__(state)¶
Appropriately reset state.
- property default¶
The default value of the parameter.
TypeParameter
uses the default value for any type (or type pair) in the simulation state that is not explicitly set by__setitem__
orsetdefault
.Examples:
Set a default value:
langevin.gamma.default = 2.0
When the parameter is a dictionary, set defaults for zero or more keys in that dictionary:
lj.params.default = dict(epsilon=0) lj.params.default = dict(epsilon=1, sigma=1)
- get(key, default)¶
Get the value of the key with undefined keys returning default.
- Parameters:
key – Valid keys specifications (depends on the expected key length).
default – The value to default to if a key is not found in the mapping.
- Returns:
Returns the parameter value for the key when set. Otherwise, returns the provided default.
Example:
gamma_D = langevin.gamma.get("D", default=5.0)
- setdefault(key, default)¶
Set the value for the keys if not already specified.
- Parameters:
key – Valid keys specifications (depends on the expected key length).
default – The value to set when the key is not found in the mapping.
Example
langevin.gamma.setdefault("D", default=5.0)