public void SetUp() { molecule1 = builder.NewAtomContainer(); atomInMol1 = builder.NewAtom("Cl"); molecule1.Atoms.Add(atomInMol1); molecule1.Atoms.Add(builder.NewAtom("Cl")); bondInMol1 = builder.NewBond(atomInMol1, molecule1.Atoms[1]); molecule1.Bonds.Add(bondInMol1); molecule2 = builder.NewAtomContainer(); atomInMol2 = builder.NewAtom("O"); atomInMol2.ImplicitHydrogenCount = 2; molecule2.Atoms.Add(atomInMol2); moleculeSet = builder.NewChemObjectSet <IAtomContainer>(); moleculeSet.Add(molecule1); moleculeSet.Add(molecule2); reaction = builder.NewReaction(); reaction.Reactants.Add(molecule1); reaction.Products.Add(molecule2); reactionSet = builder.NewReactionSet(); reactionSet.Add(reaction); chemModel = builder.NewChemModel(); chemModel.MoleculeSet = moleculeSet; chemModel.ReactionSet = reactionSet; chemSequence1 = builder.NewChemSequence(); chemSequence1.Add(chemModel); chemSequence2 = builder.NewChemSequence(); chemFile = builder.NewChemFile(); chemFile.Add(chemSequence1); chemFile.Add(chemSequence2); }
/// <summary> /// Get the molecule 1: [C+]-C=C-C /// </summary> private IChemObjectSet <IAtomContainer> GetExampleReactants() { var setOfReactants = CDK.Builder.NewAtomContainerSet(); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms[0].FormalCharge = 1; molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Double); molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[2], molecule.Atoms[3], BondOrder.Single); try { AddExplicitHydrogens(molecule); } catch (Exception e) { Console.Out.WriteLine(e.StackTrace); } setOfReactants.Add(molecule); return(setOfReactants); }
/// <summary> /// get the molecule 1: C-C=[O+] /// /// <returns>The IAtomContainerSet</returns> /// </summary> private IChemObjectSet <IAtomContainer> GetExampleReactants() { var setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet(); IAtomContainer molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("O")); molecule.Atoms[2].FormalCharge = 1; molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Double); try { AddExplicitHydrogens(molecule); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); CDK.LonePairElectronChecker.Saturate(molecule); } catch (Exception e) { Console.Out.WriteLine(e.StackTrace); } setOfReactants.Add(molecule); return(setOfReactants); }
/// <summary> /// Get the example set of molecules. /// </summary> private IChemObjectSet <IAtomContainer> GetExampleReactants() { var setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet(); IAtomContainer molecule = builder.NewAtomContainer();//CreateFromSmiles("C-C#[O+]") molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[2], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[3], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[4], BondOrder.Single); IAtom oxy = builder.NewAtom("O"); oxy.FormalCharge = 1; molecule.Atoms.Add(oxy); molecule.AddBond(molecule.Atoms[4], molecule.Atoms[5], BondOrder.Triple); try { AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); CDK.LonePairElectronChecker.Saturate(molecule); MakeSureAtomTypesAreRecognized(molecule); } catch (CDKException e) { Console.Out.WriteLine(e.StackTrace); } setOfReactants.Add(molecule); return(setOfReactants); }
public SpanningTreeTest() { if (azulene == null) { // load azulene var filename = "NCDK.Data.MDL.azulene.mol"; var ins = ResourceLoader.GetAsStream(filename); var reader = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict); var chemFile = reader.Read(builder.NewChemFile()); var seq = chemFile[0]; var model = seq[0]; IAtomContainer azuleneMolecule = model.MoleculeSet[0]; Assert.AreEqual(10, azuleneMolecule.Atoms.Count); Assert.AreEqual(11, azuleneMolecule.Bonds.Count); azulene = new SpanningTree(azuleneMolecule); } if (ethane == null) { // create ethane IAtomContainer ethaneMolecule = builder.NewAtomContainer(); ethaneMolecule.Atoms.Add(builder.NewAtom("C")); ethaneMolecule.Atoms.Add(builder.NewAtom("C")); ethaneMolecule.AddBond(ethaneMolecule.Atoms[0], ethaneMolecule.Atoms[1], BondOrder.Single); ethane = new SpanningTree(ethaneMolecule); } }
public virtual void TestReSetFlags_IAtomContainer() { IAtomContainer atomContainer = builder.NewAtomContainer(); IAtom atom1 = builder.NewAtom("C"); atom1.IsVisited = true; IAtom atom2 = builder.NewAtom("C"); atom2.IsVisited = true; IBond bond1 = builder.NewBond(atom1, atom2, BondOrder.Single); atomContainer.Atoms.Add(atom1); atomContainer.Atoms.Add(atom2); atomContainer.Bonds.Add(bond1); PathTools.ResetFlags(atomContainer); // now assume that no VISITED is set IEnumerator <IAtom> atoms = atomContainer.Atoms.GetEnumerator(); while (atoms.MoveNext()) { Assert.IsFalse(atoms.Current.IsVisited); } IEnumerator <IBond> bonds = atomContainer.Bonds.GetEnumerator(); while (bonds.MoveNext()) { Assert.IsFalse(bonds.Current.IsVisited); } }
public void TestWriting() { StringWriter writer = new StringWriter(); var molecule = builder.NewAtomContainer(); IAtom atom1 = builder.NewAtom("C"); atom1.Point3D = new Vector3(1.0, 2.0, 3.0); IAtom atom2 = builder.NewAtom("C"); atom2.Point3D = new Vector3(1.0, 2.0, 3.0); molecule.Atoms.Add(atom1); molecule.Atoms.Add(atom2); XYZWriter xyzWriter = new XYZWriter(writer); xyzWriter.Write(molecule); xyzWriter.Close(); writer.Close(); string output = writer.ToString(); // Debug.WriteLine(output); // count lines int lineCount = 0; var reader = new StringReader(output); while (reader.ReadLine() != null) { lineCount++; } Assert.AreEqual(4, lineCount); }
public void TestCalculatePiElectronegativity_IAtomContainer_IAtom() { PiElectronegativity pe = new PiElectronegativity(); IAtomContainer molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("F")); molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single); AddExplicitHydrogens(molecule); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); CDK.LonePairElectronChecker.Saturate(molecule); for (int i = 0; i < molecule.Atoms.Count; i++) { if (i == 0) { Assert.AreNotSame(0.0, pe.CalculatePiElectronegativity(molecule, molecule.Atoms[i])); } else { Assert.AreEqual(0.0, pe.CalculatePiElectronegativity(molecule, molecule.Atoms[i]), 0.001); } } }
public void TestStabilityAfterRoundtrip() { var filename = "NCDK.Data.MDL.bug1014344-1.mol"; var ins = ResourceLoader.GetAsStream(filename); var reader = new MDLReader(ins, ChemObjectReaderMode.Strict); var mol1 = reader.Read(builder.NewAtomContainer()); AddImplicitHydrogens(mol1); var output = new StringWriter(); var cmlWriter = new CMLWriter(output); cmlWriter.Write(mol1); var cmlreader = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(output.ToString()))); var mol2 = ((IChemFile)cmlreader.Read(builder.NewChemFile()))[0][0].MoleculeSet[0]; AddImplicitHydrogens(mol2); labeler.CanonLabel(mol1); labeler.CanonLabel(mol2); var atoms1 = mol1.Atoms.GetEnumerator(); var atoms2 = mol2.Atoms.GetEnumerator(); while (atoms1.MoveNext()) { atoms2.MoveNext(); var atom1 = atoms1.Current; var atom2 = atoms2.Current; Assert.AreEqual(atom1.GetProperty <long>(InvPair.CanonicalLabelPropertyKey), atom2.GetProperty <long>(InvPair.CanonicalLabelPropertyKey)); } }
private IChemObjectSet <IAtomContainer> GetExampleReactants() { var setOfReactants = CDK.Builder.NewAtomContainerSet(); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[2], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[3], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[3], molecule.Atoms[4], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[3], molecule.Atoms[5], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[3], molecule.Atoms[6], BondOrder.Single); IAtom atom = molecule.Atoms[0]; molecule.SingleElectrons.Add(CDK.Builder.NewSingleElectron(atom)); try { MakeSureAtomTypesAreRecognized(molecule); } catch (CDKException e) { Console.Out.WriteLine(e.StackTrace); } setOfReactants.Add(molecule); return(setOfReactants); }
public void Test_WithNInChI() { string mdlInput = // same as NC1=CC(N)=NC(O)=N1 "\n" + " Mrv0541 02151109592D\n" + "\n" + " 9 9 0 0 0 0 999 V2000\n" + " 2.1434 -0.4125 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 1.4289 -0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 0.7145 -0.4125 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 0.0000 -0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n" + " -0.7145 -0.4125 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 0.0000 0.8250 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 0.7145 1.2375 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 0.7145 2.0625 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 1.4289 0.8250 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 1 2 1 0 0 0 0\n" + " 2 3 2 0 0 0 0\n" + " 3 4 1 0 0 0 0\n" + " 4 5 1 0 0 0 0\n" + " 4 6 2 0 0 0 0\n" + " 6 7 1 0 0 0 0\n" + " 7 8 1 0 0 0 0\n" + " 7 9 2 0 0 0 0\n" + " 2 9 1 0 0 0 0\n" + "M END\n"; var reader = new MDLV2000Reader(new StringReader(mdlInput)); var molecule = reader.Read(builder.NewAtomContainer()); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); var hAdder = CDK.HydrogenAdder; hAdder.AddImplicitHydrogens(molecule); var tautomers = tautomerGenerator.GetTautomers(molecule); // InChI will be calculated Assert.AreEqual(5, tautomers.Count); }
static InductivePartialChargesTest() { mol = builder.NewAtomContainer(); IAtom atom1 = builder.NewAtom("C"); IAtom atom2 = builder.NewAtom("Cl"); IAtom atom3 = builder.NewAtom("Br"); IAtom atom4 = builder.NewAtom("H"); IAtom atom5 = builder.NewAtom("O"); atom5.Point3D = new Vector3(2.24, 1.33, 0.0); atom1.Point3D = new Vector3(1.80, 0.0, 0.0); atom2.Point3D = new Vector3(0.0, 0.0, 0.0); atom3.Point3D = new Vector3(2.60, -0.79, 1.59); atom4.Point3D = new Vector3(2.15, -0.60, -0.87); IBond bond1 = builder.NewBond(atom1, atom2, BondOrder.Single); IBond bond2 = builder.NewBond(atom1, atom3, BondOrder.Single); IBond bond3 = builder.NewBond(atom1, atom4, BondOrder.Single); IBond bond4 = builder.NewBond(atom1, atom5, BondOrder.Single); mol.Atoms.Add(atom1); mol.Atoms.Add(atom2); mol.Atoms.Add(atom3); mol.Atoms.Add(atom4); mol.Atoms.Add(atom5); mol.Bonds.Add(bond1); mol.Bonds.Add(bond2); mol.Bonds.Add(bond3); mol.Bonds.Add(bond4); }
private IChemObjectSet <IAtomContainer> GetExampleReactants() { var setOfReactants = CDK.Builder.NewAtomContainerSet(); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("O")); molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[1], molecule.Atoms[3], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[1], molecule.Atoms[4], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[2], molecule.Atoms[5], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[2], molecule.Atoms[6], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[2], molecule.Atoms[7], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[8], BondOrder.Single); IAtom atom = molecule.Atoms[0]; atom.FormalCharge = 1; molecule.SingleElectrons.Add(CDK.Builder.NewSingleElectron(atom)); setOfReactants.Add(molecule); return(setOfReactants); }
public void TestCalculateNumberOfImplicitHydrogens() { IChemObjectBuilder builder = ChemObjectBuilder.Instance; IAtomContainer proton = builder.NewAtomContainer(); IAtom hplus = builder.NewAtom("H"); hplus.FormalCharge = 1; proton.Atoms.Add(hplus); Assert.AreEqual(0, satcheck.CalculateNumberOfImplicitHydrogens(hplus, proton)); IAtomContainer hydrogenRadical = builder.NewAtomContainer(); IAtom hradical = builder.NewAtom("H"); hydrogenRadical.Atoms.Add(hradical); hydrogenRadical.SingleElectrons.Add(builder.NewSingleElectron(hradical)); Assert.AreEqual(0, satcheck.CalculateNumberOfImplicitHydrogens(hradical, hydrogenRadical)); IAtomContainer hydrogen = builder.NewAtomContainer(); IAtom h = builder.NewAtom("H"); hydrogen.Atoms.Add(h); Assert.AreEqual(1, satcheck.CalculateNumberOfImplicitHydrogens(h, hydrogen)); IAtomContainer coRad = builder.NewAtomContainer(); IAtom c = builder.NewAtom("C"); IAtom o = builder.NewAtom("O"); IBond bond = builder.NewBond(c, o, BondOrder.Double); coRad.Atoms.Add(c); coRad.Atoms.Add(o); coRad.Bonds.Add(bond); coRad.SingleElectrons.Add(builder.NewSingleElectron(c)); Assert.AreEqual(1, satcheck.CalculateNumberOfImplicitHydrogens(c, coRad)); }
public void TestTermination() { int ringSize = 7; var ring = builder.NewAtomContainer(); for (int i = 0; i < ringSize; i++) { ring.Atoms.Add(builder.NewAtom("C")); } for (int j = 0; j < ringSize - 1; j++) { ring.AddBond(ring.Atoms[j], ring.Atoms[j + 1], BondOrder.Single); } ring.AddBond(ring.Atoms[ringSize - 1], ring.Atoms[0], BondOrder.Single); ring.Atoms.Add(builder.NewAtom("Cl")); ring.Atoms.Add(builder.NewAtom("F")); ring.AddBond(ring.Atoms[0], ring.Atoms[ringSize], BondOrder.Single); ring.AddBond(ring.Atoms[0], ring.Atoms[ringSize + 1], BondOrder.Single); ring.Atoms.Add(builder.NewAtom("O")); ring.AddBond(ring.Atoms[1], ring.Atoms[ringSize + 2], BondOrder.Single); var atoms = new IAtom[] { ring.Atoms[ringSize], ring.Atoms[ringSize + 1], ring.Atoms[ringSize - 1], ring.Atoms[1] }; var stereoCenter = new TetrahedralChirality(ring.Atoms[0], atoms, TetrahedralStereo.AntiClockwise); ring.StereoElements.Add(stereoCenter); SmilesGenerator generator = new SmilesGenerator(); CIPTool.GetCIPChirality(ring, stereoCenter); }
public static void PartitionRingsFromComplexRing(string dataFile) { var som = builder.NewAtomContainerSet(); try { Console.Out.WriteLine("Start..."); using (var fin = new StreamReader(dataFile)) using (var imdl = new EnumerableSDFReader(fin, builder)) { Console.Out.Write("Read File in.."); Console.Out.WriteLine("READY"); foreach (var m in imdl) { Console.Out.WriteLine($"Atoms: {m.Atoms.Count}"); IRingSet ringSetM = Cycles.FindSSSR(m).ToRingSet(); // som.Add(m); for (int i = 0; i < ringSetM.Count; i++) { som.Add(builder.NewAtomContainer(ringSetM[i])); } } } } catch (Exception exc) { Console.Out.WriteLine($"Could not read Molecules from file {dataFile} due to: {exc.Message}"); } Console.Out.WriteLine($"{som.Count} Templates are read in"); WriteChemModel(som, dataFile, "_VERSUCH"); }
/// <summary> /// Get the Acetaldehyde structure. /// </summary> // @cdk.inchi InChI=1/C2H4O/c1-2-3/h2H,1H3 private IChemObjectSet <IAtomContainer> GetExampleReactants() { var setOfReactants = CDK.Builder.NewAtomContainerSet(); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("O")); molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Double); molecule.Atoms.Add(builder.NewAtom("C")); molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single); molecule.Atoms.Add(builder.NewAtom("H")); molecule.Atoms.Add(builder.NewAtom("H")); molecule.Atoms.Add(builder.NewAtom("H")); molecule.Atoms.Add(builder.NewAtom("H")); molecule.AddBond(molecule.Atoms[1], molecule.Atoms[3], BondOrder.Single); molecule.AddBond(molecule.Atoms[2], molecule.Atoms[4], BondOrder.Single); molecule.AddBond(molecule.Atoms[2], molecule.Atoms[5], BondOrder.Single); molecule.AddBond(molecule.Atoms[2], molecule.Atoms[6], BondOrder.Single); try { AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); CDK.LonePairElectronChecker.Saturate(molecule); } catch (CDKException e) { Console.Out.WriteLine(e.StackTrace); } setOfReactants.Add(molecule); return(setOfReactants); }
public void TestReading() { var filename = "NCDK.Data.ASN.PubChem.cid1145.xml"; Trace.TraceInformation("Testing: " + filename); var ins = ResourceLoader.GetAsStream(filename); PCCompoundXMLReader reader = new PCCompoundXMLReader(ins); IAtomContainer molecule = (IAtomContainer)reader.Read(builder.NewAtomContainer()); reader.Close(); Assert.IsNotNull(molecule); // check atom stuff Assert.AreEqual(14, molecule.Atoms.Count); Assert.AreEqual("O", molecule.Atoms[0].Symbol); Assert.AreEqual(-1, molecule.Atoms[0].FormalCharge); Assert.AreEqual("N", molecule.Atoms[1].Symbol); Assert.AreEqual(1, molecule.Atoms[1].FormalCharge); // check bond stuff Assert.AreEqual(13, molecule.Bonds.Count); Assert.IsNotNull(molecule.Bonds[3]); // coordinates Assert.IsNull(molecule.Atoms[0].Point3D); var npoint = molecule.Atoms[0].Point2D; Assert.IsNotNull(npoint); var point = npoint.Value; Assert.AreEqual(3.7320508956909, point.X, 0.00000001); Assert.AreEqual(0.5, point.Y, 0.00000001); }
public void TestGetSource() { IAtomContainer expResult = builder.NewAtomContainer(); handler.Source = expResult; IAtomContainer result = handler.Source; Assert.AreEqual(expResult, result); }
public void TestGetAtomContainer_IChemObjectBuilder() { var parser = new InChIToStructure("InChI=1S/CH5/h1H4", builder); var container = parser.AtomContainer; // test if the created IAtomContainer is done with the Silent module... // OK, this is not typical use, but maybe the above generate method should be private Assert.IsInstanceOfType(container, builder.NewAtomContainer().GetType()); }
public void TestNewAtomContainer_IAtomContainer() { IChemObjectBuilder builder = RootObject.Builder; IAtomContainer container = builder.NewAtomContainer(); Assert.IsNotNull(container); IAtomContainer second = builder.NewAtomContainer(container); Assert.IsNotNull(second); }
public override void TestInitiate_IAtomContainerSet_IAtomContainerSet() { /* Ionize(>C=O): C=CCC(=O)CC -> C=CCC(=O*)CC , set the reactive center */ var reactant = builder.NewAtomContainer();//CreateFromSmiles("C=CCC(=O)CC") reactant.Atoms.Add(builder.NewAtom("C")); reactant.Atoms.Add(builder.NewAtom("C")); reactant.Atoms.Add(builder.NewAtom("C")); reactant.Atoms.Add(builder.NewAtom("C")); reactant.Atoms.Add(builder.NewAtom("O")); reactant.Atoms.Add(builder.NewAtom("C")); reactant.Atoms.Add(builder.NewAtom("C")); reactant.AddBond(reactant.Atoms[0], reactant.Atoms[1], BondOrder.Double); reactant.AddBond(reactant.Atoms[1], reactant.Atoms[2], BondOrder.Single); reactant.AddBond(reactant.Atoms[2], reactant.Atoms[3], BondOrder.Single); reactant.AddBond(reactant.Atoms[3], reactant.Atoms[4], BondOrder.Double); reactant.AddBond(reactant.Atoms[3], reactant.Atoms[5], BondOrder.Single); reactant.AddBond(reactant.Atoms[5], reactant.Atoms[6], BondOrder.Single); AddExplicitHydrogens(reactant); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactant); CDK.LonePairElectronChecker.Saturate(reactant); foreach (var atom in reactant.Atoms) { if (reactant.GetConnectedLonePairs(atom).Count() > 0) { atom.IsReactiveCenter = true; } } var setOfReactants = CDK.Builder.NewAtomContainerSet(); setOfReactants.Add(reactant); /* initiate */ MakeSureAtomTypesAreRecognized(reactant); var type = new ElectronImpactNBEReaction(); var paramList = new List <IParameterReaction>(); var param = new SetReactionCenter { IsSetParameter = true }; paramList.Add(param); type.ParameterList = paramList; var setOfReactions = type.Initiate(setOfReactants, null); Assert.AreEqual(1, setOfReactions.Count); Assert.AreEqual(1, setOfReactions[0].Products.Count); var molecule = setOfReactions[0].Products[0]; Assert.AreEqual(1, molecule.Atoms[4].FormalCharge.Value); Assert.AreEqual(1, molecule.GetConnectedSingleElectrons(molecule.Atoms[4]).Count()); Assert.IsTrue(setOfReactions[0].Mappings.Any()); }
public void XtestPyrrole() { var enol = builder.NewAtomContainer(); // atom block var atom1 = builder.NewAtom(ChemicalElement.C); atom1.Hybridization = Hybridization.SP2; var atom2 = builder.NewAtom(ChemicalElement.C); atom2.Hybridization = Hybridization.SP2; var atom3 = builder.NewAtom(ChemicalElement.C); atom3.Hybridization = Hybridization.SP2; var atom4 = builder.NewAtom(ChemicalElement.C); atom4.Hybridization = Hybridization.SP2; var atom5 = builder.NewAtom(ChemicalElement.N); atom5.Hybridization = Hybridization.SP2; atom5.ImplicitHydrogenCount = 1; // bond block var bond1 = builder.NewBond(atom1, atom2); var bond2 = builder.NewBond(atom2, atom3); var bond3 = builder.NewBond(atom3, atom4); var bond4 = builder.NewBond(atom4, atom5); var bond5 = builder.NewBond(atom5, atom1); enol.Atoms.Add(atom1); enol.Atoms.Add(atom2); enol.Atoms.Add(atom3); enol.Atoms.Add(atom4); enol.Atoms.Add(atom5); enol.Bonds.Add(bond1); enol.Bonds.Add(bond2); enol.Bonds.Add(bond3); enol.Bonds.Add(bond4); enol.Bonds.Add(bond5); // perceive atom types AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(enol); // now have the algorithm have a go at it enol = FixBondOrdersTool.KekuliseAromaticRings(enol); Assert.IsNotNull(enol); //Assert.IsTrue(FixBondOrdersTool.IsOK(enol)); // now check whether it did the right thing Assert.AreEqual(BondOrder.Double, enol.Bonds[0].Order);; Assert.AreEqual(BondOrder.Single, enol.Bonds[1].Order);; Assert.AreEqual(BondOrder.Double, enol.Bonds[2].Order);; Assert.AreEqual(BondOrder.Single, enol.Bonds[3].Order);; Assert.AreEqual(BondOrder.Single, enol.Bonds[4].Order);; }
public void Test968852() { var filename = "NCDK.Data.MDL.2,5-dimethyl-furan.mol"; var ins = ResourceLoader.GetAsStream(filename); var reader = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict); IAtomContainer mol1 = reader.Read(builder.NewAtomContainer()); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol1); Aromaticity.CDKLegacy.Apply(mol1); Assert.AreEqual(new HOSECodeGenerator().GetHOSECode(mol1, mol1.Atoms[2], 6), new HOSECodeGenerator().GetHOSECode(mol1, mol1.Atoms[3], 6)); }
public void TestReadingIDs() { var filename = "NCDK.Data.Mol2.fromWebsite.mol2"; IAtomContainer molecule; using (var reader = new Mol2Reader(ResourceLoader.GetAsStream(filename))) { molecule = reader.Read(builder.NewAtomContainer()); } Assert.IsNotNull(molecule); var reference = (IAtomContainer)molecule.Clone(); Assert.AreEqual("C1", reference.Atoms[0].Id); }
private IAtomContainer Create4Toluene() { IAtomContainer result = builder.NewAtomContainer(); IAtom c1 = builder.NewAtom("C"); c1.Id = "1"; IAtom c2 = builder.NewAtom("C"); c2.Id = "2"; IAtom c3 = builder.NewAtom("C"); c3.Id = "3"; IAtom c4 = builder.NewAtom("C"); c4.Id = "4"; IAtom c5 = builder.NewAtom("C"); c5.Id = "5"; IAtom c6 = builder.NewAtom("C"); c6.Id = "6"; IAtom c7 = builder.NewAtom("C"); c7.Id = "7"; result.Atoms.Add(c1); result.Atoms.Add(c2); result.Atoms.Add(c3); result.Atoms.Add(c4); result.Atoms.Add(c5); result.Atoms.Add(c6); result.Atoms.Add(c7); IBond bond1 = builder.NewBond(c1, c2, BondOrder.Single); IBond bond2 = builder.NewBond(c2, c3, BondOrder.Double); IBond bond3 = builder.NewBond(c3, c4, BondOrder.Single); IBond bond4 = builder.NewBond(c4, c5, BondOrder.Double); IBond bond5 = builder.NewBond(c5, c6, BondOrder.Single); IBond bond6 = builder.NewBond(c6, c1, BondOrder.Double); IBond bond7 = builder.NewBond(c7, c4, BondOrder.Single); result.Bonds.Add(bond1); result.Bonds.Add(bond2); result.Bonds.Add(bond3); result.Bonds.Add(bond4); result.Bonds.Add(bond5); result.Bonds.Add(bond6); result.Bonds.Add(bond7); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(result); return(result); }
public void TestCarbons() { IReactionProcess type = new SharingAnionReaction(); IAtomContainer molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms[0].FormalCharge = 1; molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms[1].FormalCharge = -1; molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single); AddExplicitHydrogens(molecule); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule); CDK.LonePairElectronChecker.Saturate(molecule); var setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet(); setOfReactants.Add(molecule); /* initiate */ var paramList = new List <IParameterReaction>(); var param = new SetReactionCenter(); param.IsSetParameter = false; paramList.Add(param); type.ParameterList = paramList; var setOfReactions = type.Initiate(setOfReactants, null); Assert.AreEqual(1, setOfReactions.Count); Assert.AreEqual(1, setOfReactions[0].Products.Count); IAtomContainer product = setOfReactions[0].Products[0]; IAtomContainer molecule2 = builder.NewAtomContainer(); molecule2.Atoms.Add(builder.NewAtom("C")); molecule2.Atoms.Add(builder.NewAtom("C")); molecule2.AddBond(molecule2.Atoms[0], molecule2.Atoms[1], BondOrder.Double); AddExplicitHydrogens(molecule2); AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule2); CDK.LonePairElectronChecker.Saturate(molecule2); IQueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product); Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom)); }
public IAtomContainer ParseMolecule(XElement parser, IChemObjectBuilder builder) { IAtomContainer molecule = builder.NewAtomContainer(); // assume the current element is PC-Compound if (!parser.Name.Equals(Name_EL_PCCOMPOUND)) { return(null); } foreach (var elm in parser.Descendants(Name_EL_ATOMBLOCK)) { ParserAtomBlock(elm, molecule); } foreach (var elm in parser.Descendants(Name_EL_BONDBLOCK)) { ParserBondBlock(elm, molecule); } foreach (var elm in parser.Descendants(Name_EL_COORDINATESBLOCK)) { ParserCoordBlock(elm, molecule); } foreach (var elm in parser.Descendants(Name_EL_PROPS_INFODATA)) { ParserCompoundInfoData(elm, molecule); } foreach (var elm in parser.Descendants(Name_EL_PCCOMPOUND_ID)) { string cid = GetCID(elm); molecule.SetProperty("PubChem CID", cid); } return(molecule); }
public void TestRebond_IAtomContainer() { var rebonder = new RebondTool(2.0, 0.5, 0.5); var methane = builder.NewAtomContainer(); methane.Atoms.Add(builder.NewAtom("C", new Vector3(0.0, 0.0, 0.0))); methane.Atoms.Add(builder.NewAtom("H", new Vector3(0.6, 0.6, 0.6))); methane.Atoms.Add(builder.NewAtom("H", new Vector3(-0.6, -0.6, 0.6))); methane.Atoms.Add(builder.NewAtom("H", new Vector3(0.6, -0.6, -0.6))); methane.Atoms.Add(builder.NewAtom("H", new Vector3(-0.6, 0.6, -0.6))); // configure atoms var factory = AtomTypeFactory.GetInstance("NCDK.Config.Data.jmol_atomtypes.txt"); //IAtom[] atoms = methane.GetAtoms(); for (int i = 0; i < methane.Atoms.Count; i++) { factory.Configure(methane.Atoms[i]); } // rebond rebonder.Rebond(methane); Assert.AreEqual(5, methane.Atoms.Count); Assert.AreEqual(4, methane.Bonds.Count); }
/// <summary> /// Extract the cyclic atom and bond fragments of the container. Bonds which /// join two different isolated/fused cycles (e.g. biphenyl) are not be /// included. /// </summary> /// <returns>a new container with only the cyclic atoms and bonds</returns> /// <seealso cref="SpanningTree.GetCyclicFragmentsContainer"/>> public IAtomContainer RingFragments() { var vertices = Cyclic(); int n = vertices.Length; var atoms = new IAtom[n]; List <IBond> bonds = new List <IBond>(); for (int i = 0; i < vertices.Length; i++) { atoms[i] = container.Atoms[vertices[i]]; } var abonds = container.Bonds; foreach (var bond in abonds) { IAtom either = bond.Begin; IAtom other = bond.End; int u = container.Atoms.IndexOf(either); int v = container.Atoms.IndexOf(other); // add the bond if the vertex colors match if (searcher.Cyclic(u, v)) { bonds.Add(bond); } } IChemObjectBuilder builder = container.Builder; IAtomContainer fragment = builder.NewAtomContainer(atoms, bonds); return(fragment); }