public void TestGetAllAtomMapping() { var sp = new SmilesParser(ChemObjectBuilder.Instance, false); var target = sp.ParseSmiles("C\\C=C/Nc1cccc(c1)N(O)\\C=C\\C\\C=C\\C=C/C"); var queryac = sp.ParseSmiles("Nc1ccccc1"); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(target); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(queryac); Aromaticity.CDKLegacy.Apply(target); Aromaticity.CDKLegacy.Apply(queryac); ExtAtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(queryac); ExtAtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(target); // Calling the main algorithm to perform MCS cearch Aromaticity.CDKLegacy.Apply(queryac); Aromaticity.CDKLegacy.Apply(target); Isomorphism smsd1 = new Isomorphism(Algorithm.Default, true); smsd1.Init(queryac, target, true, true); smsd1.SetChemFilters(true, true, true); Assert.IsNotNull(smsd1.GetFirstMapping()); Assert.AreEqual(2, smsd1.GetAllAtomMapping().Count); }
public void TestCBrIFCl() { var molecule = smiles.ParseSmiles("FC(Br)(Cl)I"); var ligandF = new Ligand(molecule, new VisitedAtoms(), molecule.Atoms[1], molecule.Atoms[0]); var ligandBr = new Ligand(molecule, new VisitedAtoms(), molecule.Atoms[1], molecule.Atoms[2]); var ligandCl = new Ligand(molecule, new VisitedAtoms(), molecule.Atoms[1], molecule.Atoms[3]); var ligandI = new Ligand(molecule, new VisitedAtoms(), molecule.Atoms[1], molecule.Atoms[4]); var rule = new CIPLigandRule(); Assert.AreEqual(-1, rule.Compare(ligandF, ligandI)); Assert.AreEqual(-1, rule.Compare(ligandF, ligandBr)); Assert.AreEqual(-1, rule.Compare(ligandF, ligandCl)); Assert.AreEqual(-1, rule.Compare(ligandCl, ligandI)); Assert.AreEqual(-1, rule.Compare(ligandCl, ligandBr)); Assert.AreEqual(-1, rule.Compare(ligandBr, ligandI)); var ligands = new List <ILigand> { ligandI, ligandBr, ligandF, ligandCl }; ligands.Sort(new CIPLigandRule()); Assert.AreEqual("F", ligands[0].LigandAtom.Symbol); Assert.AreEqual("Cl", ligands[1].LigandAtom.Symbol); Assert.AreEqual("Br", ligands[2].LigandAtom.Symbol); Assert.AreEqual("I", ligands[3].LigandAtom.Symbol); }
public string CanonicalStringFromSmiles(string smiles) { var mol = parser.ParseSmiles(smiles); MoleculeSignature signature = new MoleculeSignature(mol); return(signature.ToCanonicalString()); }
public void TestDetection() { TemplateHandler th = new TemplateHandler(); var smiles = "CC12C3(C6CC6)C4(C)C1C5(C(CC)C)C(C(CC)C)2C(C)3C45CC(C)C"; var mol = sp.ParseSmiles(smiles); Assert.IsTrue(th.MapTemplates(mol)); }
public void TestCalculateOverlapsAndReduce() { var sp = new SmilesParser(builder); var Molecule1 = sp.ParseSmiles("O1C=CC=C1"); var Molecule2 = sp.ParseSmiles("C1CCCC1"); CDKRMapHandler instance = new CDKRMapHandler(); instance.CalculateOverlapsAndReduce(Molecule1, Molecule2, true); Assert.IsNotNull(FinalMappings.Instance.Count); }
static void Main() { #region SmilesParser sp = new SmilesParser(); IAtomContainer atomContainer = sp.ParseSmiles("CC(=O)OC(=O)C"); // acetic acid anhydride IAtomContainer SMILESquery = sp.ParseSmiles("CC"); // acetic acid anhydride IQueryAtomContainer query = QueryAtomContainerCreator.CreateBasicQueryContainer(SMILESquery); bool isSubstructure = CDKMCS.IsSubgraph(atomContainer, query, true); #endregion }
private ICollection <IAtomContainer> UnitTestWithInChIProvided(string smiles, string inchi, int tautCountExpected) { var container = smilesParser.ParseSmiles(smiles); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(container); var tautomers = tautomerGenerator.GetTautomers(container, inchi); Assert.AreEqual(tautCountExpected, tautomers.Count); return(tautomers); }
public void Fulvelene1() { int[][] graph = GraphUtil.ToAdjList(smipar.ParseSmiles("c1cccc1c1cccc1")); Matching m = Matching.WithCapacity(graph.Length); BitArray subset = new BitArray(graph.Length); BitArrays.Flip(subset, 0, graph.Length); // arbitary matching will assign a perfect matching here Assert.IsTrue(m.ArbitaryMatching(graph, subset)); }
private static IReadOnlyList <ILigand> MakeLigands() { molecule = smiles.ParseSmiles("ClC(Br)(I)[H]"); var visitedAtoms = new VisitedAtoms(); var ligand1 = new Ligand(molecule, visitedAtoms, molecule.Atoms[1], molecule.Atoms[4]); var ligand2 = new Ligand(molecule, visitedAtoms, molecule.Atoms[1], molecule.Atoms[3]); var ligand3 = new Ligand(molecule, visitedAtoms, molecule.Atoms[1], molecule.Atoms[2]); var ligand4 = new Ligand(molecule, visitedAtoms, molecule.Atoms[1], molecule.Atoms[0]); return(new ILigand[] { ligand1, ligand2, ligand3, ligand4 }); }
public void TestCalculateOverlapsAndReduceExactMatch() { var sp = new SmilesParser(builder); var Molecule1 = sp.ParseSmiles("O1C=CC=C1"); var Molecule2 = sp.ParseSmiles("O1C=CC=C1"); CDKRMapHandler instance = new CDKRMapHandler(); instance.CalculateOverlapsAndReduceExactMatch(Molecule1, Molecule2, true); // TODO review the generated test code and remove the default call to fail. Assert.IsNotNull(FinalMappings.Instance.Count); }
public void TestGetMappings() { var sp = new SmilesParser(builder); var Molecule1 = sp.ParseSmiles("O1C=CC=C1"); var Molecule2 = sp.ParseSmiles("O1C=CC=C1"); CDKRMapHandler instance = new CDKRMapHandler(); instance.CalculateOverlapsAndReduceExactMatch(Molecule1, Molecule2, true); var result = instance.Mappings; Assert.AreEqual(2, result.Count); }
static void Main() { UniversalIsomorphismTester universalIsomorphismTester = new UniversalIsomorphismTester(); #region SmilesParser sp = new SmilesParser(); IAtomContainer atomContainer = sp.ParseSmiles("CC(=O)OC(=O)C"); // acetic acid anhydride IAtomContainer SMILESquery = sp.ParseSmiles("CC"); // ethylene IQueryAtomContainer query = QueryAtomContainerCreator.CreateBasicQueryContainer(SMILESquery); bool isSubstructure = universalIsomorphismTester.IsSubgraph(atomContainer, query); #endregion }
public void TestTPSA1() { var mol = sp.ParseSmiles("O=C(O)CC"); AddExplicitHydrogens(mol); Assert.AreEqual(37.29, CreateDescriptor().Calculate(mol).Value, 0.01); }
/// <summary> /// Update the template library - can be called for safety after /// each load. /// </summary> public void Update() { var smipar = new SmilesParser(); var updated = new MultiDictionary <string, Vector2[]>(); foreach (var e in templateMap) { try { var mol = smipar.ParseSmiles(e.Key); var order = new int[mol.Atoms.Count]; var key = CreateCanonicalSmiles(mol, order); foreach (var coords in e.Value) { updated.Add(key, ReorderCoords(coords, order)); } } catch (CDKException ex) { Console.Error.WriteLine(e.Key + " could not be updated: " + ex.Message); } } templateMap.Clear(); foreach (var e in updated) { foreach (var v in e.Value) { templateMap.Add(e.Key, v); } } }
private IAtomContainer LoadSmi(string smi) { var mol = smipar.ParseSmiles(smi); AtomContainerManipulator.ConvertImplicitToExplicitHydrogens(mol); return(mol); }
private void AssertSmiles(string smi, int expected) { SmilesParser smipar = CDK.SmilesParser; var mol = smipar.ParseSmiles(smi); Assert.AreEqual(expected.ToString(), CreateDescriptor().Calculate(mol).Value.ToString()); }
static void Main() { { #region SmilesParser sp = new SmilesParser(); IAtomContainer atomContainer = sp.ParseSmiles("CC(=O)OC(=O)C"); SMARTSQueryTool querytool = new SMARTSQueryTool("O=CO"); bool status = querytool.Matches(atomContainer); if (status) { int nmatch = querytool.MatchesCount; var mappings = querytool.GetMatchingAtoms(); foreach (var atomIndices in mappings) { // do something } } #endregion } { string someSmartsPattern = null; IChemObjectSet <IAtomContainer> molecules = null; #region SetAromaticity SMARTSQueryTool sqt = new SMARTSQueryTool(someSmartsPattern); sqt.SetAromaticity(new Aromaticity(ElectronDonation.CDKModel, Cycles.CDKAromaticSetFinder)); foreach (var molecule in molecules) { // CDK Aromatic model needs atom types AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); sqt.Matches(molecule); } #endregion } }
/// <summary> /// SmilesToAtomContainer /// </summary> /// <param name="smiles"></param> /// <returns></returns> public static IAtomContainer SmilesToAtomContainer(string smiles) { try { SmilesParser sp = new SmilesParser(ChemObjectBuilder.Instance); IAtomContainer mol = sp.ParseSmiles(smiles); // may get "could not parse error" for some CorpIds, e.g.: 111, 222, 333 if (mol == null) { return(null); } ConfigureAtomContainer(mol); return(mol); } catch (Exception ex) { ParseSmilesErrorCount++; LastParseSmilesError = ex.Message; throw new Exception(ex.Message, ex); } }
// compute the invariants for the first atom in a SMILES string static SMARTSAtomInvariants InvariantOfFirstAtom(string smiles) { var container = sp.ParseSmiles(smiles); SMARTSAtomInvariants.ConfigureDaylightWithRingInfo(container); return(container.Atoms[0].GetProperty <SMARTSAtomInvariants>(SMARTSAtomInvariants.Key)); }
// create a container from a smiles string protected static IAtomContainer Smi(string smi) { var container = sp.ParseSmiles(smi); container.Title = smi; return(container); }
private static void CheckFPSmartsForMolecule(string moleculeSmiles, string[][] expectedFPSmarts) { var expected = new HashSet <string>(); foreach (var strs in expectedFPSmarts) { foreach (var str in strs) { expected.Add(str); } } // expectedFPSmarts[][] is a double array because for each smarts // several equivalent variants // of the smarts are given e.g. CCC C(C)C var mol = parser.ParseSmiles(moleculeSmiles); CircularFingerprinter circ = new CircularFingerprinter(); circ.Calculate(mol); var subsmarts = new SmartsFragmentExtractor(mol); subsmarts.SetMode(SubstructureSelectionMode.JCompoundMapper); var numFP = circ.FPCount; var actual = new HashSet <string>(); for (int i = 0; i < numFP; i++) { var fp = circ.GetFP(i); actual.Add(subsmarts.Generate(fp.Atoms)); } Assert.IsTrue(expected.IsSupersetOf(actual)); }
public void TestSplit() { var mol = smilesParser.ParseSmiles("C1CC1C2CCC2"); SpanningTree st = new SpanningTree(mol); IRingSet rings = st.GetAllRings(); IBond splitBond = null; for (int i = 0; i < mol.Bonds.Count; i++) { if (rings.GetRings(mol.Bonds[i]).Count() == 0) { splitBond = mol.Bonds[i]; break; } } var frags = FragmentUtils.SplitMolecule(mol, splitBond); SmilesGenerator sg = new SmilesGenerator(); var uniqueFrags = new HashSet <string>(); foreach (var frag in frags) { uniqueFrags.Add(sg.Create(frag)); } Assert.AreEqual(2, uniqueFrags.Count); // You can put the fragments back together with a ring closure and dot // [CH]12CC1.[CH]12CCC1 Assert.IsTrue(uniqueFrags.IsSupersetOf(new[] { "[CH]1CC1", "[CH]1CCC1" })); }
/// <summary> /// Read the file content into a <see cref="IAtomContainerSet"/>. /// </summary> /// <param name="molSet">an <see cref="IAtomContainerSet"/> to store the structures</param> /// <returns>the <see cref="IAtomContainerSet"/> containing the molecules read in</returns> /// <exception cref="IOException">if there is an error during reading</exception> private IChemObjectSet <IAtomContainer> ReadAtomContainerSet(IChemObjectSet <IAtomContainer> molSet) { SmilesParser parser = new SmilesParser(molSet.Builder, false); string line = input.ReadLine(); line = input.ReadLine(); // skip the first line while (line != null) { string[] cols = line.Split(','); try { var mol = parser.ParseSmiles(cols[1]); mol.SetProperty("focusSupport", cols[5]); mol.SetProperty("complementSupport", cols[7]); mol.SetProperty("atomCount", cols[2]); mol.SetProperty("bondCount", cols[3]); molSet.Add(mol); } catch (InvalidSmilesException exception) { Trace.TraceError($"Skipping invalid SMILES: {cols[1]}"); Debug.WriteLine(exception); } line = input.ReadLine(); } return(molSet); }
public void TestCanonLabel_IAtomContainer() { var molecule = parser.ParseSmiles("CC(=O)CBr"); labeler.CanonLabel(molecule); foreach (var atom in molecule.Atoms) { Assert.IsNotNull(atom.GetProperty <long?>(InvPair.CanonicalLabelPropertyKey)); } Assert.AreEqual(3, molecule.Atoms[0].GetProperty <long>(InvPair.CanonicalLabelPropertyKey)); Assert.AreEqual(2, molecule.Atoms[1].GetProperty <long>(InvPair.CanonicalLabelPropertyKey)); Assert.AreEqual(1, molecule.Atoms[2].GetProperty <long>(InvPair.CanonicalLabelPropertyKey)); Assert.AreEqual(4, molecule.Atoms[3].GetProperty <long>(InvPair.CanonicalLabelPropertyKey)); Assert.AreEqual(5, molecule.Atoms[4].GetProperty <long>(InvPair.CanonicalLabelPropertyKey)); }
public void TestEF1() { var mol = smilesParser.ParseSmiles("CCC"); fragmenter.GenerateFragments(mol); var frags = fragmenter.GetFragments(); Assert.AreEqual(0, frags.Count()); }
public void TestGetMatrix_IAtomContainer() { var container = sp.ParseSmiles("C1CC1"); double[][] matrix = ConnectionMatrix.GetMatrix(container); Assert.AreEqual(3, matrix.Length); Assert.AreEqual(3, matrix[0].Length); }
public void TestPartitionExtendedTetrahedral() { SmilesParser smipar = CDK.SmilesParser; var container = smipar.ParseSmiles("CC=[C@]=CC.C"); IChemObjectSet <IAtomContainer> containerSet = ConnectivityChecker.PartitionIntoMolecules(container); Assert.AreEqual(2, containerSet.Count); Assert.IsTrue(containerSet[0].StereoElements.GetEnumerator().MoveNext()); }
public static void Script8_3() { var parser = new SmilesParser(); var hAdder = CDKHydrogenAdder.GetInstance(); var methanol = parser.ParseSmiles("CO"); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(methanol); hAdder.AddImplicitHydrogens(methanol); AtomContainerManipulator.ConvertImplicitToExplicitHydrogens(methanol); var dimethoxymethane = parser.ParseSmiles("COC"); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(dimethoxymethane); hAdder.AddImplicitHydrogens(dimethoxymethane); AtomContainerManipulator.ConvertImplicitToExplicitHydrogens(dimethoxymethane); var water = parser.ParseSmiles("O"); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(water); hAdder.AddImplicitHydrogens(water); AtomContainerManipulator.ConvertImplicitToExplicitHydrogens(water); var reaction = new Reaction(); reaction.Reactants.Add(methanol, 2.0D); reaction.Products.Add(dimethoxymethane); reaction.Products.Add(water); Console.WriteLine("Reactants:"); foreach (var reactant in reaction.Reactants) { var formula = MolecularFormulaManipulator.GetMolecularFormula(reactant); Console.WriteLine(MolecularFormulaManipulator.GetString(formula)); } Console.WriteLine("Products: "); foreach (var product in reaction.Products) { var formula = MolecularFormulaManipulator.GetMolecularFormula(product); Console.WriteLine(MolecularFormulaManipulator.GetString(formula)); } }
public void TestGenerateFingerprintIsNotASubSet1() { string smilesT = "O[C@H]1[C@H](O)[C@@H](O)[C@H](O)[C@H](O)[C@@H]1O"; string smilesQ = "OC[C@@H](O)[C@@H](O)[C@H](O)[C@@H](O)C(O)=O"; var smilesParser = new SmilesParser(builder, false); var moleculeQ = smilesParser.ParseSmiles(smilesQ); var moleculeT = smilesParser.ParseSmiles(smilesT); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(moleculeQ); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(moleculeT); ShortestPathFingerprinter fingerprint = new ShortestPathFingerprinter(1024); BitArray fingerprintQ; BitArray fingerprintT; fingerprintQ = fingerprint.GetBitFingerprint(moleculeQ).AsBitSet(); fingerprintT = fingerprint.GetBitFingerprint(moleculeT).AsBitSet(); Assert.IsFalse(FingerprinterTool.IsSubset(fingerprintT, fingerprintQ)); }
private void Test(string expected, string smi, params ExprType[] opts) { var mol = smipar.ParseSmiles(smi); Cycles.MarkRingAtomsAndBonds(mol); var query = QueryAtomContainer.Create(mol, opts); var actual = Smarts.Generate(query); Assert.AreEqual(expected, actual); }