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); }
/// <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); } } }
/// <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); }
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); } }
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()); }
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 MoleculeSignatureTest() { this.parser = CDK.SmilesParser; this.builder = ChemObjectBuilder.Instance; mol = builder.NewAtomContainer(); mol.Atoms.Add(builder.NewAtom("C")); mol.Atoms.Add(builder.NewAtom("C")); mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Single); molSig = new MoleculeSignature(mol); }
public void TestRing() { sp = CDK.SmilesParser; var mol = sp.ParseSmiles("C1CCCC1CCC2CCCNC2"); AddExplicitHydrogens(mol); var dv = CreateDescriptor().Calculate(mol); Assert.IsNotNull(dv); }
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 }
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 Guanine_ket() { var smipar = new SmilesParser(builder); var smiles = "NC1=NC2=C(N=CN2)C(=O)N1"; var mol = smipar.ParseSmiles(smiles); var inchiFact = InChIGeneratorFactory.Instance; var inchigen = inchiFact.GetInChIGenerator(mol, "KET"); Assert.AreEqual(InChIReturnCode.Ok, inchigen.ReturnStatus); Assert.AreEqual("InChI=1/C5H5N5O/c6-5-9-3-2(4(11)10-5)7-1-8-3/h1H,(H4,2,6,7,8,9,10,11)", inchigen.InChI); }
public void InliningReactionsWithRadicals() { IChemObjectBuilder bldr = ChemObjectBuilder.Instance; SmilesParser smipar = new SmilesParser(bldr); IReaction reaction = smipar.ParseReactionSmiles("[CH2]CO.CC(=O)O>[H+]>CCOC(=O)C.O |^1:0| ethyl esterification"); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.CxSmiles); // convert to molecule IAtomContainer mol = ReactionManipulator.ToMolecule(reaction); Assert.AreEqual("[CH2]CO.CC(=O)O.[H+].CCOC(=O)C.O |^1:0|", smigen.Create(mol)); Assert.AreEqual("[CH2]CO.CC(=O)O>[H+]>CCOC(=O)C.O |^1:0|", smigen.CreateReactionSMILES(ReactionManipulator.ToReaction(mol))); }
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 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); }
public void TestConstructorAndGetMethods() { SmilesParser smiles = CDK.SmilesParser; var molecule = smiles.ParseSmiles("ClC(Br)(I)"); ILigand ligand = new ImplicitHydrogenLigand(molecule, new VisitedAtoms(), molecule.Atoms[1]); Assert.IsNotNull(ligand); Assert.AreEqual(molecule, ligand.AtomContainer); Assert.AreEqual(molecule.Atoms[1], ligand.CentralAtom); Assert.IsTrue(ligand.LigandAtom is ImmutableHydrogen); }
public void Aminopropenol_15T() { var builder = CDK.Builder; var smipar = new SmilesParser(builder); var smiles = "N\\C=C/C=O"; var mol = smipar.ParseSmiles(smiles); var inchiFact = InChIGeneratorFactory.Instance; var inchigen = inchiFact.GetInChIGenerator(mol, "15T"); Assert.AreEqual(InChIReturnCode.Ok, inchigen.ReturnStatus); Assert.AreEqual("InChI=1/C3H5NO/c4-2-1-3-5/h1-3H,(H2,4,5)", inchigen.InChI); }
public static IAtomContainer ConvertSMILES(string smilesString) { if (string.IsNullOrWhiteSpace(smilesString)) { return(null); } var bldr = ChemObjectBuilder.Instance; var smipar = new SmilesParser(bldr); var mol = smipar.ParseSmiles(smilesString); return(mol); }
public void Timeout() { var smipar = new SmilesParser(builder); var smiles = "C(CCCNC(=N)N)(COCC(COP([O])(=O)OCCCCCCNC(NC1=CC(=C(C=C1)C2(C3=CC=C(C=C3OC=4C2=CC=C(C4)O)O)C)C(=O)[O])=S)OP(=O)([O])OCC(COCC(CCC/[NH]=C(\\[NH])/N)(CCCNC(=N)N)CCCNC(=N)N)OP(=O)([O])OCC(COCC(CCCNC(=N)N)(CCC/[NH]=C(\\[NH])/N)CCCNC(=N)N)OP(OCC(COCC(CCCNC(=N)N)(CCCNC(=N)N)CCC/[NH]=C(\\[NH])/N)OP(=O)([O])OCC(COCC(CCCNC(=N)N)(CCCNC(N)=N)CCC/[NH]=C(/N)\\[NH])OP([O])(=O)CCC(COCC(CCCNC(=N)N)(CCC/[NH]=C(\\[NH])/N)CCCNC(=N)N)OP([O])(=O)OCC(COCC(CCCNC(N)=N)(CCCNC(N)=N)CCC/[NH]=C(\\[NH])/N)OP(OCC(COCC(CCCNC(N)=N)(CCC/[NH]=C(/N)\\[NH])CCCNC(N)=N)O=P([O])(OCC(COP(=OC(COCC(CCC/[NH]=C(\\[NH])/N)(CCCNC(N)=N)CCCNC(N)=N)COP([O])(=O)OC(COP(OC(COCC(CCCNC(=N)N)(CCC/[NH]=C(\\[NH])/N)CCCNC(=N)N)COP(OC(COCC(CCCNC(=N)N)(CCC/[NH]=C(\\[NH])/N)CCCNC(=N)N)COP([O])(=O)OC(COP(OC(COP(OC(COP(=O)([O])OC(COCC(CCC/[NH]=C(/N)\\[NH])(CCCNC(N)=N)CCCNC(=N)N)COP([O])(=O)OCCCCCCNC(NC=5C=CC(=C(C5)C(=O)[O])C6(C7=CC=C(C=C7OC=8C6=CC=C(C8)O)O)C)=S)COCC(CCCNC(N)=N)(CCC/[NH]=C(\\[NH])/N)CCCNC(=N)N)([O])=O)COCC(CCCNC(=N)N)(CCC/[NH]=C(\\[NH])/N)CCCNC(=N)N)([O])=O)COCC(CCCNC(=N)N)(CCCNC(=N)N)CCC/[NH]=C(\\[NH])/N)([O])=O)([O])=O)COCC(CCC/[NH]=C(/N)\\[NH])(CCCNC(=N)N)CCCNC(=N)N)([O])[O])(C)COP(OCCCCCCO)(=O)[O])[O])(=O)[O])([O])=O)(CCC/[NH]=C(\\[NH])/[NH])CCCNC(=N)N"; var mol = smipar.ParseSmiles(smiles); var inchiFact = InChIGeneratorFactory.Instance; var generator = inchiFact.GetInChIGenerator(mol, "W0.01"); Assert.AreEqual(InChIReturnCode.Error, generator.ReturnStatus); Assert.IsTrue( generator.Log.Contains("Time limit exceeded") || generator.Log.Contains("Structure normalization timeout")); }
public void HydrogenAsFirstAtomInEthane() { SmilesParser smipar = CDK.SmilesParser; var ethane = smipar.ParseSmiles("[H]C([H])([H])C([H])([H])[H]"); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(ethane); ModelBuilder3D mb3d = ModelBuilder3D.GetInstance(); mb3d.Generate3DCoordinates(ethane, false); foreach (var atom in ethane.Atoms) { Assert.IsNotNull(atom.Point3D); } }
void Main() { UniversalIsomorphismTester universalIsomorphismTester = null; #region 1 SmilesParser sp = new SmilesParser(); IAtomContainer atomContainer = sp.ParseSmiles("CC(=O)OC(=O)C"); QueryAtomContainer query = SMARTSParser.Parse("C*C"); bool queryMatch = universalIsomorphismTester.IsSubgraph(atomContainer, query); #endregion #region 2 SMARTSParser parser = new SMARTSParser(new StringReader("C*C")); ASTStart start = parser.Start(); #endregion }
public void TestSMARTS() { var sp = new SmilesParser(); var atomContainer = sp.ParseSmiles("CC(=O)OC(=O)C"); // acetic acid anhydride var query = new QueryAtomContainer(); var atom1 = new NCDK.Isomorphisms.Matchers.SMARTS.AnyAtom(); var atom2 = new SymbolQueryAtom() { Symbol = "C" }; query.Atoms.Add(atom1); query.Atoms.Add(atom2); query.Bonds.Add(new NCDK.Isomorphisms.Matchers.OrderQueryBond(atom1, atom2, BondOrder.Double)); Assert.IsTrue(uiTester.IsSubgraph(atomContainer, query)); }
static void Main() { { IAtomContainer container = null; IAtom atom1 = null; IAtom atom2 = null; #region 1 AtomContainerManipulator.ReplaceAtomByAtom(container, atom1, atom2); #endregion } #region SetSingleOrDoubleFlags SmilesParser parser = new SmilesParser(ChemObjectBuilder.Instance, false); IAtomContainer biphenyl = parser.ParseSmiles("c1cccc(c1)c1ccccc1"); AtomContainerManipulator.SetSingleOrDoubleFlags(biphenyl); #endregion }
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)); } }
static void Main() { #region var smipar = new SmilesParser(); IAtomContainer mol = smipar.ParseSmiles("[nH]1ccc2c1cccc2"); var subsmarts = new SmartsFragmentExtractor(mol); string smarts; // smarts=[nH1v3X3+0][cH1v4X3+0][cH1v4X3+0][cH0v4X3+0] // hits =1 smarts = subsmarts.Generate(new int[] { 0, 1, 3, 4 }); subsmarts.SetMode(SubstructureSelectionMode.JCompoundMapper); // smarts=n(ccc(a)a)a // hits = 0 - one of the 'a' atoms needs to match the nitrogen smarts = subsmarts.Generate(new int[] { 0, 1, 3, 4 }); #endregion }
void Main() { { #region 1 SmilesParser sp = new SmilesParser(); IAtomContainer m = sp.ParseSmiles("c1[cH:5]cccc1"); var c1 = m.Atoms[1].GetProperty <int>(CDKPropertyName.AtomAtomMapping); // 5 var c2 = m.Atoms[2].GetProperty <int>(CDKPropertyName.AtomAtomMapping); // null #endregion } { #region 2 SmilesParser sp = new SmilesParser(); IAtomContainer m = sp.ParseSmiles("c1[cH:5]cccc1"); var c1 = m.Atoms[1].GetProperty <int>(CDKPropertyName.AtomAtomMapping); // 5 var c2 = m.Atoms[2].GetProperty <int>(CDKPropertyName.AtomAtomMapping); // null #endregion } }
public void Ctor() { #region SmilesParser sp = new SmilesParser(); IAtomContainer ac = sp.ParseSmiles("CC"); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(ac); AtomContainerManipulator.ConvertImplicitToExplicitHydrogens(ac); MMFF94PartialCharges mmff = new MMFF94PartialCharges(); mmff.AssignMMFF94PartialCharges(ac); #endregion foreach (var atom in ac.Atoms) { Console.WriteLine( #region result atom.GetProperty <double>("MMFF94charge") #endregion ); } }
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)); }
[TestMethod(), Ignore()] // Failing but not going to be fixed public void TestGetAllMapping() { 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); MCSPlusHandler smsd1 = new MCSPlusHandler(); MolHandler mol1 = new MolHandler(queryac, true, true); MolHandler mol2 = new MolHandler(target, true, true); smsd1.Set(mol1, mol2); smsd1.SearchMCS(true); Assert.IsNotNull(smsd1.GetFirstMapping()); Assert.AreEqual(4, smsd1.GetAllMapping().Count); }