def max_translate(self, max_translate): max_translate = validate_unit_list( max_translate, (self._n_boxes, self._n_species), dimensions.length, "max_translate", ) for max_val in max_translate.flatten(): if max_val.to_value() < 0.0: raise ValueError( "Max translation values cannot be less than zero") self._max_translate = max_translate
def max_dihedral(self, max_dihedral): max_dihedral = validate_unit_list( max_dihedral, (self._n_species, ), dimensions.angle, "max_dihedral", ) for max_val in max_dihedral: if (max_val.to_value("degree") < 0.0 or max_val.to_value("degree") > 360.0): raise ValueError( "Max dihedral rotation values must be between 0.0 and 360.0 degrees." ) self._max_dihedral = max_dihedral
def max_rotate(self, max_rotate): max_rotate = validate_unit_list( max_rotate, (self._n_boxes, self._n_species), dimensions.angle, "max_rotate", ) for max_val in max_rotate.flatten(): if (max_val.to_value("degree") < 0.0 or max_val.to_value("degree") > 360.0): raise ValueError( "Max rotation values must be between 0.0 and 360.0 degrees." ) self._max_rotate = max_rotate
def cbmc_rcut(self, cbmc_rcut): if type(cbmc_rcut) not in (list, u.unyt_array): cbmc_rcut = [cbmc_rcut] * self._n_boxes cbmc_rcut = validate_unit_list( cbmc_rcut, (self._n_boxes, ), dimensions.length, "cbmc_rcut", ) for rcut in cbmc_rcut.flatten(): if rcut.to_value() < 0.0: raise ValueError("cbmc_rcut cannot be less than zero.") self._cbmc_rcut = cbmc_rcut
def max_volume(self, max_volume): if type(max_volume) not in (list, u.unyt_array): if self.ensemble == "gemc_npt": max_volume = [max_volume] * self._n_boxes else: max_volume = [max_volume] if self.ensemble == "gemc_npt": shape = (self._n_boxes, ) else: shape = (1, ) max_volume = validate_unit_list( max_volume, shape, dimensions.length**3, "max_volume", ) for max_vol in max_volume.flatten(): if max_vol < 0.0: raise ValueError("max_volume cannot be less than zero.") self._max_volume = max_volume
def test_validate_unit_list(self): list_ = [3.0 * u.angstrom, 1.0 * u.angstrom, 1.5 * u.angstrom] with pytest.raises(TypeError): validate_unit_list(list_, (2, ), dimensions.length)
def test_validate_unit_list(self, unit_list, shape, dimension): unit_list = validate_unit_list(unit_list, shape, dimension) assert type(unit_list) == u.unyt_array assert unit_list.units.dimensions == dimension assert unit_list.shape == shape
def test_mismatch_unit_list(self, unit_list, shape, dimension): with pytest.raises(IterableUnitCoercionError): validate_unit_list(unit_list, shape, dimension)
def test_invalid_unit_list(self, unit_list, shape, dimension): with pytest.raises(TypeError, match="argument must be a list"): validate_unit_list(unit_list, shape, dimension)