public void TestTwoVersusDoubleBondedOxygen() { var molecule = smiles.ParseSmiles("OC(O)C([H])(C)C=O"); var ligand1 = CIPTool.DefineLigand(molecule, new VisitedAtoms(), 3, 1); var ligand2 = CIPTool.DefineLigand(molecule, new VisitedAtoms(), 3, 6); var rule = new CIPLigandRule(); Assert.AreEqual(-1, rule.Compare(ligand1, ligand2)); Assert.AreEqual(1, rule.Compare(ligand2, ligand1)); }
public void TestDeepRecursion() { var molecule = smiles.ParseSmiles("CC([H])(CCCCCCCCCC)CCCCCCCCC"); var ligand1 = CIPTool.DefineLigand(molecule, new VisitedAtoms(), 1, 3); var ligand2 = CIPTool.DefineLigand(molecule, new VisitedAtoms(), 1, 13); var rule = new CIPLigandRule(); Assert.AreEqual(1, rule.Compare(ligand1, ligand2)); Assert.AreEqual(-1, rule.Compare(ligand2, ligand1)); }
public void TestSideChainsRecursive() { var molecule = smiles.ParseSmiles("CCCC([H])(C)CC"); var ligand1 = CIPTool.DefineLigand(molecule, new VisitedAtoms(), 3, 6); var ligand2 = CIPTool.DefineLigand(molecule, new VisitedAtoms(), 3, 1); var rule = new CIPLigandRule(); Assert.AreEqual(-1, rule.Compare(ligand1, ligand2)); Assert.AreEqual(1, rule.Compare(ligand2, ligand1)); }
public void TestOrder() { var molecule = smiles.ParseSmiles("CC(Br)([13C])[H]"); var ligands = new List <ILigand>(); var visitedAtoms = new VisitedAtoms(); ligands.Add(CIPTool.DefineLigand(molecule, visitedAtoms, 1, 4)); ligands.Add(CIPTool.DefineLigand(molecule, visitedAtoms, 1, 3)); ligands.Add(CIPTool.DefineLigand(molecule, visitedAtoms, 1, 2)); ligands.Add(CIPTool.DefineLigand(molecule, visitedAtoms, 1, 0)); ligands.Sort(new CIPLigandRule()); Assert.AreEqual("H", ligands[0].LigandAtom.Symbol); Assert.AreEqual("C", ligands[1].LigandAtom.Symbol); Assert.AreEqual("C", ligands[2].LigandAtom.Symbol); Assert.AreEqual(13, ligands[2].LigandAtom.MassNumber.Value); Assert.AreEqual("Br", ligands[3].LigandAtom.Symbol); }
public int Compare(ILigand ligand1, ILigand ligand2) { int numberComp = numberRule.Compare(ligand1, ligand2); if (numberComp != 0) { return(numberComp); } // OK, now I need to recurse... var ligand1Ligands = CIPTool.GetLigandLigands(ligand1); var ligand2Ligands = CIPTool.GetLigandLigands(ligand2); // if neither have ligands: if (ligand1Ligands.Count == 0 && ligand2Ligands.Count == 0) { return(0); } // else if one has no ligands if (ligand1Ligands.Count == 0) { return(-1); } if (ligand2Ligands.Count == 0) { return(1); } // ok, both have at least one ligand int minLigandCount = Math.Min(ligand1Ligands.Count, ligand2Ligands.Count); if (ligand1Ligands.Count > 1) { ligand1Ligands = Order(ligand1Ligands); } if (ligand2Ligands.Count > 1) { ligand2Ligands = Order(ligand2Ligands); } // first do a basic number rule for (int i = 0; i < minLigandCount; i++) { int comparison = numberRule.Compare(ligand1Ligands[i], ligand2Ligands[i]); if (comparison != 0) { return(comparison); } } if (ligand1Ligands.Count == ligand2Ligands.Count) { // it that does not resolve it, do a full, recursive compare for (int i = 0; i < minLigandCount; i++) { int comparison = Compare(ligand1Ligands[i], ligand2Ligands[i]); if (comparison != 0) { return(comparison); } } } // OK, if we reached this point, then the ligands they 'share' are all equals, so the one // with more ligands wins if (ligand1Ligands.Count > ligand2Ligands.Count) { return(1); } else if (ligand1Ligands.Count < ligand2Ligands.Count) { return(-1); } else { return(0); } }