Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_measurement_2args(self, protocol):
set_application_registry(self.ureg1)
m1 = Measurement(Quantity(10, "foo"), Quantity(1, "foo"))
set_application_registry(self.ureg2)
m2 = Measurement(Quantity(10, "foo"), Quantity(1, "foo"))
m3 = pickle.loads(pickle.dumps(m1, protocol))
assert m1.dimensionality == {"[dim1]": 1}
assert m2.dimensionality == {"[dim2]": 1}
assert m3.dimensionality == {"[dim2]": 1}
self.assertEqual(m1.to("bar").value.magnitude, 20)
self.assertEqual(m2.to("bar").value.magnitude, 30)
self.assertEqual(m3.to("bar").value.magnitude, 30)
self.assertEqual(m1.to("bar").error.magnitude, 2)
self.assertEqual(m2.to("bar").error.magnitude, 3)
self.assertEqual(m3.to("bar").error.magnitude, 3)
def test_measurement_2args(self, protocol):
m = Measurement(Quantity(123, "foo"), Quantity(10, "bar"))
self.assertEqual(m.value.magnitude, 123)
self.assertEqual(m.error.magnitude, 5)
self.assertEqual(str(m.units), "foo")
m = pickle.loads(pickle.dumps(m, protocol))
self.assertEqual(m.value.magnitude, 123)
self.assertEqual(m.error.magnitude, 5)
self.assertEqual(str(m.units), "foo")
iterable_values = []
if isinstance(attribute_value, AttributeClass):
attribute_value.validate(attribute_type)
elif isinstance(attribute_value, Mapping):
iterable_values = (
attribute_value[x]
for x in attribute_value
if isinstance(attribute_value[x], AttributeClass)
)
elif isinstance(attribute_value, Iterable) and not isinstance(
attribute_value, pint.Quantity
):
iterable_values = (
x for x in attribute_value if isinstance(x, AttributeClass)
)
for value in iterable_values:
value.validate()
def _add_scalebar(scalebar, neurons, method, ax):
"""Add scalebar."""
if isinstance(scalebar, bool):
scalebar = '1 um'
if isinstance(scalebar, str):
scalebar = config.ureg(scalebar)
if isinstance(scalebar, pint.Quantity):
# If we have neurons as points of reference convert
if neurons:
scalebar = scalebar.to(neurons[0].units).magnitude
# If no reference, use assume it's the same units
else:
scalebar = scalebar.magnitude
# Hard-coded offset from figure boundaries
ax_offset = (ax.get_xlim()[1] - ax.get_xlim()[0]) / 100 * 5
if method == '2d':
xlim = ax.get_xlim()
ylim = ax.get_ylim()
coords = np.array([[xlim[0] + ax_offset, ylim[0] + ax_offset],
[xlim[0] + ax_offset + scalebar, ylim[0] + ax_offset]
default_value=UNDEFINED,
)
thermodynamic_state = InputAttribute(
docstring="The thermodynamic state at which the trajectory was generated.",
type_hint=ThermodynamicState,
default_value=UNDEFINED,
)
dipole_moments = OutputAttribute(
docstring="The raw (possibly correlated) dipole moments which were used in "
"the dielectric calculation.",
type_hint=pint.Quantity,
)
volumes = OutputAttribute(
docstring="The raw (possibly correlated) which were used in the dielectric calculation.",
type_hint=pint.Quantity,
)
uncorrelated_volumes = OutputAttribute(
docstring="The uncorrelated volumes which were used in the dielectric "
"calculation.",
type_hint=pint.Quantity,
)
def _bootstrap_function(self, **sample_kwargs):
"""Calculates the static dielectric constant from an
array of dipoles and volumes.
Notes
-----
The static dielectric constant is taken from for Equation 7 of [1]
docstring="The phase / phases that this property was measured in.",
type_hint=PropertyPhase,
)
thermodynamic_state = Attribute(
docstring="The thermodynamic state that this property"
"was measured / estimated at.",
type_hint=ThermodynamicState,
)
value = Attribute(
docstring="The measured / estimated value of this property.",
type_hint=pint.Quantity,
)
uncertainty = Attribute(
docstring="The uncertainty in measured / estimated value of this property.",
type_hint=pint.Quantity,
optional=True,
)
source = Attribute(
docstring="The original source of this physical property.",
type_hint=Source,
optional=True,
)
metadata = Attribute(
docstring="Additional metadata associated with this property. All property "
"metadata will be made accessible to estimation workflows.",
type_hint=dict,
optional=True,
)
gradients = Attribute(
type_hint=dict,
default_value=default_storage_query(),
)
maximum_data_points = Attribute(
docstring="The maximum number of data points to include "
"as part of the multi-state reweighting calculations. If "
"zero, no cap will be applied.",
type_hint=int,
default_value=4,
)
temperature_cutoff = Attribute(
docstring="The maximum difference between the target temperature "
"and the temperature at which cached data was collected to. Data "
"collected for temperatures outside of this cutoff will be ignored.",
type_hint=pint.Quantity,
default_value=5.0 * unit.kelvin,
)
def validate(self, attribute_type=None):
super(ReweightingSchema, self).validate(attribute_type)
assert len(self.storage_queries) > 0
assert self.maximum_data_points > 0
assert all(
isinstance(x, SimulationDataQuery) for x in self.storage_queries.values()
)
@calculation_layer()
class ReweightingLayer(WorkflowCalculationLayer):
Parameters
----------
pint_quantity: pint.Quantity
The quantity to convert.
Returns
-------
simtk.pint.Quantity
The converted quantity.
"""
if pint_quantity is None or isinstance(pint_quantity, UndefinedAttribute):
return None
assert isinstance(pint_quantity, pint.Quantity)
pint_unit = pint_quantity.units
pint_raw_value = pint_quantity.magnitude
openmm_unit = pint_unit_to_openmm(pint_unit)
openmm_quantity = pint_raw_value * openmm_unit
return openmm_quantity
-----
Equality of two thermodynamic states is determined by comparing
the temperature in kelvin to within 3 decimal places, and comparing
the pressure (if defined) in pascals to within 3 decimal places.
Examples
--------
Specify an NPT state at 298 K and 1 atm pressure.
>>> state = ThermodynamicState(temperature=298.0*unit.kelvin, pressure=1.0*unit.atmospheres)
Note that the pressure is only relevant for periodic systems.
"""
temperature = Attribute(
docstring="The external temperature.", type_hint=pint.Quantity
)
pressure = Attribute(
docstring="The external pressure.", type_hint=pint.Quantity, optional=True
)
@property
def inverse_beta(self):
"""Returns the temperature multiplied by the molar gas constant"""
return (self.temperature * unit.molar_gas_constant).to(
unit.kilojoule / unit.mole
)
@property
def beta(self):
"""Returns one divided by the temperature multiplied by the molar gas constant"""
return 1.0 / self.inverse_beta