コード例 #1
0
 def test_chem_comp(self):
     """Test ChemComp class"""
     cc1 = ihm.ChemComp(id='GLY', code='G', code_canonical='G')
     self.assertEqual(cc1.id, 'GLY')
     self.assertEqual(cc1.code, 'G')
     self.assertEqual(cc1.code_canonical, 'G')
     self.assertEqual(cc1.type, 'other')
     self.assertIsNone(cc1.formula)
     self.assertIsNone(cc1.formula_weight)
     cc2 = ihm.ChemComp(id='GLY', code='G', code_canonical='G')
     cc3 = ihm.ChemComp(id='G', code='G', code_canonical='G')
     self.assertEqual(cc1, cc2)
     self.assertEqual(hash(cc1), hash(cc2))
     self.assertNotEqual(cc1, cc3)
コード例 #2
0
 def test_chem_comp_weight(self):
     """Test ChemComp.formula_weight"""
     # No formula
     cc = ihm.ChemComp('X', 'X', 'X', formula=None)
     self.assertIsNone(cc.formula_weight)
     # Bad formula
     cc = ihm.ChemComp('X', 'X', 'X', formula='C90H')
     self.assertRaises(ValueError, lambda x: x.formula_weight, cc)
     # Formula with unknown element
     cc = ihm.ChemComp('X', 'X', 'X', formula='C5 Y')
     self.assertIsNone(cc.formula_weight)
     # Formula with known elements and no charge
     cc = ihm.ChemComp('X', 'X', 'X', formula='C6 H12 P')
     self.assertAlmostEqual(cc.formula_weight, 115.136, places=2)
     # Formula with known elements and formal charge
     cc = ihm.ChemComp('X', 'X', 'X', formula='C6 H12 P 1')
     self.assertAlmostEqual(cc.formula_weight, 115.136, places=2)