def testInvalidRxn(self): """IsValid() should flag up invalid reaction data""" mol = pybel.readstring("smi", "CC>>O").OBMol facade = ob.OBReactionFacade(mol) self.assertTrue(facade.IsValid()) mol.SetIsReaction(False) self.assertFalse(facade.IsValid()) mol.SetIsReaction() self.assertTrue(facade.IsValid()) atom = mol.GetAtom(1) facade.SetRole(atom, 4) self.assertFalse(facade.IsValid()) # invalid role facade.SetRole(atom, ob.REACTANT) self.assertTrue(facade.IsValid()) data = atom.GetData("rxncomp") ob.toPairInteger(data).SetValue(-1) self.assertFalse(facade.IsValid()) # invalid rxn component id atom.DeleteData(data) self.assertFalse(atom.HasData("rxncomp")) self.assertFalse(facade.IsValid()) # data missing newdata = ob.OBPairData() newdata.SetAttribute("rxncomp") newdata.SetValue("1") atom.CloneData(newdata) self.assertTrue(atom.HasData("rxncomp")) self.assertFalse(facade.IsValid()) # wrong type of data # Connected component should not belong to two different # rxn components or two different reaction roles mol = pybel.readstring("smi", "CC>>O").OBMol facade = ob.OBReactionFacade(mol) self.assertTrue(facade.IsValid()) atom = mol.GetAtom(1) facade.SetComponentId(atom, 99) self.assertFalse(facade.IsValid()) facade.SetComponentId(atom, 1) self.assertTrue(facade.IsValid()) facade.SetRole(atom, ob.AGENT) self.assertFalse(facade.IsValid())
def testSMILES(self): mol = pybel.readstring("smi", "C[CH3:6]") atom = mol.OBMol.GetAtom(2) data = atom.GetData("Atom Class") self.assertTrue(data) self.assertEqual(6, ob.toPairInteger(data).GetGenericValue()) atom.DeleteData("Atom Class") ac = ob.OBPairInteger() ac.SetAttribute("Atom Class") ac.SetValue(2) mol.OBMol.GetAtom(1).CloneData(ac) out = mol.write("smi", opt={"a": True, "n": True, "nonewline": True}) self.assertEqual("[CH3:2]C", out)
def testSMILES(self): mol = pybel.readstring("smi", "C[CH3:6]") atom = mol.OBMol.GetAtom(2) data = atom.GetData("Atom Class") self.assertTrue(data) self.assertEqual(6, ob.toPairInteger(data).GetGenericValue()) atom.DeleteData("Atom Class") ac = ob.obpairtemplateint() ac.SetAttribute("Atom Class") ac.SetValue(2) mol.OBMol.GetAtom(1).CloneData(ac) out = mol.write("smi", opt={"a":True, "n":True, "nonewline":True}) self.assertEqual("[CH3:2]C", out)