Exemplo n.º 1
0
    def test_add_delete_cosmetic_attributes(self):
        """Test ParameterHandler.to_dict() function when some parameters are in
        different units (proper behavior is to convert all quantities to the last-
        read unit)
        """
        from simtk import unit
        bh = BondHandler(skip_version_check=True)
        bh.add_parameter({
            'smirks': '[*:1]-[*:2]',
            'length': 1 * unit.angstrom,
            'k': 10 * unit.kilocalorie_per_mole / unit.angstrom**2
        })
        bh.add_parameter({
            'smirks': '[*:1]=[*:2]',
            'length': 0.2 * unit.nanometer,
            'k': 0.4 * unit.kilojoule_per_mole / unit.nanometer**2
        })

        assert not (bh.attribute_is_cosmetic('pilot'))

        # Ensure the cosmetic attribute is present by default during output
        bh.add_cosmetic_attribute('pilot', 'alice')
        param_dict = bh.to_dict()
        assert ('pilot', 'alice') in param_dict.items()
        assert bh.attribute_is_cosmetic('pilot')

        # Ensure the cosmetic attribute isn't present if we request that it be discarded
        param_dict = bh.to_dict(discard_cosmetic_attributes=True)
        assert 'pilot' not in param_dict

        # Manually delete the cosmetic attribute and ensure it doesn't get written out
        bh.delete_cosmetic_attribute('pilot')
        param_dict = bh.to_dict()
        assert 'pilot' not in param_dict
        assert not (bh.attribute_is_cosmetic('pilot'))
Exemplo n.º 2
0
 def test_to_dict_maintain_units(self):
     """Test ParameterHandler.to_dict() function when parameters were provided in different units
     """
     from simtk import unit
     bh = BondHandler(skip_version_check=True)
     bh.add_parameter({'smirks': '[*:1]-[*:2]',
                       'length': 1*unit.angstrom,
                       'k': 10*unit.kilocalorie_per_mole/unit.angstrom**2})
     bh.add_parameter({'smirks': '[*:1]=[*:2]',
                       'length': 0.2*unit.nanometer,
                       'k': 0.4*unit.kilojoule_per_mole/unit.nanometer**2})
     bh_dict = bh.to_dict()
     assert bh_dict['Bond'][0]['length'] == unit.Quantity(1., unit.angstrom)
     assert bh_dict['Bond'][0]['length'].unit == unit.angstrom
     assert bh_dict['Bond'][1]['length'] == unit.Quantity(0.2, unit.nanometer)
     assert bh_dict['Bond'][1]['length'].unit == unit.nanometer
Exemplo n.º 3
0
 def test_different_units_to_dict(self):
     """Test ParameterHandler.to_dict() function when some parameters are in
     different units (proper behavior is to convert all quantities to the last-
     read unit)
     """
     from simtk import unit
     bh = BondHandler(skip_version_check=True)
     bh.add_parameter({'smirks': '[*:1]-[*:2]',
                       'length': 1*unit.angstrom,
                       'k': 10*unit.kilocalorie_per_mole/unit.angstrom**2})
     bh.add_parameter({'smirks': '[*:1]=[*:2]',
                       'length': 0.2*unit.nanometer,
                       'k': 0.4*unit.kilojoule_per_mole/unit.nanometer**2})
     bh_dict = bh.to_dict()
     assert bh_dict['Bond'][0]['length'] == unit.Quantity(value=1, unit=unit.angstrom)
     assert bh_dict['Bond'][1]['length'] == unit.Quantity(value=2, unit=unit.angstrom)