public override void StartDocument() { ChemFile = new ChemFile(); chemSequence = new ChemSequence(); chemModel = new ChemModel(); setOfMolecules = new ChemObjectSet <IAtomContainer>(); }
public void TestAlign() { { IAtomContainer ac; var filename = "NCDK.Data.HIN.gravindex.hin"; var ins = ResourceLoader.GetAsStream(filename); ISimpleChemObjectReader reader = new HINReader(ins); ChemFile content = (ChemFile)reader.Read((ChemObject) new ChemFile()); var cList = ChemFileManipulator.GetAllAtomContainers(content); ac = cList.First(); KabschAlignment ka = new KabschAlignment(ac, ac); Assert.IsNotNull(ka); ka.Align(); double rmsd = ka.RMSD; Assert.IsTrue(1e-8 > rmsd); Assert.IsNotNull(ka.RotationMatrix); } { double[][] p1 = new[] { new[] { 16.754, 20.462, 45.049 }, new[] { 19.609, 18.145, 46.011 }, new[] { 17.101, 17.256, 48.707 }, new[] { 13.963, 18.314, 46.820 }, new[] { 14.151, 15.343, 44.482 }, new[] { 14.959, 12.459, 46.880 }, new[] { 11.987, 13.842, 48.862 }, new[] { 9.586, 12.770, 46.123 }, new[] { 11.006, 9.245, 46.116 }, new[] { 10.755, 9.090, 49.885 } }; double[][] p2 = new[] { new[] { 70.246, 317.510, 188.263 }, new[] { 73.457, 317.369, 190.340 }, new[] { 71.257, 318.976, 193.018 }, new[] { 68.053, 317.543, 191.651 }, new[] { 68.786, 313.954, 192.637 }, new[] { 70.248, 314.486, 196.151 }, new[] { 67.115, 316.584, 196.561 }, new[] { 64.806, 313.610, 196.423 }, new[] { 66.804, 311.735, 199.035 }, new[] { 66.863, 314.832, 201.113 } }; Atom[] a1 = new Atom[10]; Atom[] a2 = new Atom[10]; for (int i = 0; i < 10; i++) { a1[i] = new Atom("C"); Vector3 newCoord = new Vector3 { X = p1[i][0], Y = p1[i][1], Z = p1[i][2] }; a1[i].Point3D = newCoord; a2[i] = new Atom("C"); newCoord = new Vector3 { X = p2[i][0], Y = p2[i][1], Z = p2[i][2] }; a2[i].Point3D = newCoord; } var ka = new KabschAlignment(a1, a2); ka.Align(); var rmsd = ka.RMSD; Assert.AreEqual(0.13479726, rmsd, 0.00000001); } }
public void TestBug2846213() { var filename = "NCDK.Data.MDL.bug2846213.mol"; var ins = ResourceLoader.GetAsStream(filename); var reader = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict); ChemFile chemFile = (ChemFile)reader.Read((ChemObject) new ChemFile()); IAtomContainer ac = ChemFileManipulator.GetAllAtomContainers(chemFile).First(); long[] morganNumbers = MorganNumbersTools.GetMorganNumbers(ac); Assert.IsFalse(morganNumbers[7] == morganNumbers[8]); }
public void TestIsConnectedFromSDFile() { var filename = "NCDK.Data.MDL.mdeotest.sdf"; var ins = ResourceLoader.GetAsStream(filename); ISimpleChemObjectReader reader = new MDLV2000Reader(ins); ChemFile content = (ChemFile)reader.Read((ChemObject) new ChemFile()); var cList = ChemFileManipulator.GetAllAtomContainers(content); IAtomContainer ac = cList.First(); Assert.IsTrue(ConnectivityChecker.IsConnected(ac), "Molecule appears not to be connected"); }
public void TestAtomProperties() { var filename = "NCDK.Data.CML.custompropertiestest.cml"; var ins = ResourceLoader.GetAsStream(filename); var reader = new CMLReader(ins); ChemFile chemFile = (ChemFile)reader.Read((ChemFile) new ChemFile()); reader.Close(); Assert.IsNotNull(chemFile); IAtomContainer container = ChemFileManipulator.GetAllAtomContainers(chemFile).First(); for (int i = 0; i < container.Atoms.Count; i++) { Assert.AreEqual(2, container.Atoms[i].GetProperties().Count); } }
public void TestNMRReading() { IAtomContainer atomContainer = null; //bool foundOneShieldingEntry = false; //Double shielding = null; object obj = null; int shieldingCounter = 0; var filename = "NCDK.Data.Gaussian.g98ReaderNMRTest.log"; var ins = ResourceLoader.GetAsStream(filename); var inputReader = new StreamReader(ins); Gaussian98Reader g98Reader = new Gaussian98Reader(inputReader); ChemFile chemFile = (ChemFile)g98Reader.Read(new ChemFile()); g98Reader.Close(); var atomContainersList = ChemFileManipulator.GetAllAtomContainers(chemFile); Assert.IsNotNull(atomContainersList); Assert.IsTrue(atomContainersList.Count() == 54); //Debug.WriteLine("Found " + atomContainers.Length + " atomContainers"); int counter = 0; foreach (var ac in atomContainersList) { shieldingCounter = 0; atomContainer = ac; for (int g = 0; g < atomContainer.Atoms.Count; g++) { obj = atomContainer.Atoms[g].GetProperty <double?>(CDKPropertyName.IsotropicShielding); if (obj != null) { //shielding = (double)object; shieldingCounter++; } } if (counter < 53) { Assert.IsTrue(shieldingCounter == 0); } else { Assert.IsTrue(shieldingCounter == ac.Atoms.Count); } //Debug.WriteLine("AtomContainer " + (f + 1) + " has " + atomContainers[f].Atoms.Count + " atoms and " + shieldingCounter + " shielding entries"); counter++; } }
public override void EndDocument() { ChemFile.Add(chemSequence); }
/// <summary> Creates amino acid AminoAcid objects. /// /// </summary> /// <returns> aminoAcids, a HashMap containing the amino acids as AminoAcids. /// </returns> public static AminoAcid[] createAAs() { if (aminoAcids != null) { return aminoAcids; } // Create set of AtomContainers aminoAcids = new AminoAcid[20]; IChemFile list = new ChemFile(); //UPGRADE_ISSUE: Method 'java.lang.ClassLoader.getResourceAsStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassLoader'" //UPGRADE_ISSUE: Method 'java.lang.Class.getClassLoader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassgetClassLoader'" CMLReader reader = new CMLReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + "list_aminoacids.cml"));//typeof(AminoAcids).getClassLoader().getResourceAsStream("data/templates/list_aminoacids.cml")); try { list = (IChemFile)reader.read(list); IAtomContainer[] containers = ChemFileManipulator.getAllAtomContainers(list); for (int i = 0; i < containers.Length; i++) { //logger.debug("Adding AA: ", containers[i]); // convert into an AminoAcid AminoAcid aminoAcid = new AminoAcid(); IAtom[] atoms = containers[i].Atoms; System.Collections.IEnumerator props = containers[i].Properties.Keys.GetEnumerator(); //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'" while (props.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'" System.Object next = props.Current; //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" //logger.debug("Prop class: " + next.GetType().FullName); //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" //logger.debug("Prop: " + next.ToString()); if (next is DictRef) { DictRef dictRef = (DictRef)next; // System.out.println("DictRef type: " + dictRef.getType()); if (dictRef.Type.Equals("pdb:residueName")) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" aminoAcid.setProperty(RESIDUE_NAME, containers[i].getProperty(dictRef).ToString().ToUpper()); } else if (dictRef.Type.Equals("pdb:oneLetterCode")) { aminoAcid.setProperty(RESIDUE_NAME_SHORT, containers[i].getProperty(dictRef)); } else if (dictRef.Type.Equals("pdb:id")) { aminoAcid.setProperty(ID, containers[i].getProperty(dictRef)); //logger.debug("Set AA ID to: ", containers[i].getProperty(dictRef)); } else { //logger.error("Cannot deal with dictRef!"); } } } for (int atomCount = 0; atomCount < atoms.Length; atomCount++) { IAtom atom = atoms[atomCount]; System.String dictRef = (System.String)atom.getProperty("org.openscience.cdk.dict"); if (dictRef != null && dictRef.Equals("pdb:nTerminus")) { aminoAcid.addNTerminus(atom); } else if (dictRef != null && dictRef.Equals("pdb:cTerminus")) { aminoAcid.addCTerminus(atom); } else { aminoAcid.addAtom(atom); } } IBond[] bonds = containers[i].Bonds; for (int bondCount = 0; bondCount < bonds.Length; bondCount++) { aminoAcid.addBond(bonds[bondCount]); } AminoAcidManipulator.removeAcidicOxygen(aminoAcid); aminoAcid.setProperty(NO_ATOMS, "" + aminoAcid.AtomCount); aminoAcid.setProperty(NO_BONDS, "" + aminoAcid.getBondCount()); if (i < aminoAcids.Length) { aminoAcids[i] = aminoAcid; } else { //logger.error("Could not store AminoAcid! Array too short!"); } } } catch (System.Exception exception) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" //logger.error("Failed reading file: ", exception.Message); //logger.debug(exception); } return aminoAcids; }
#pragma warning disable CA1810 // Initialize reference type static fields inline static AminoAcids() #pragma warning restore CA1810 // Initialize reference type static fields inline { // Create set of AtomContainers proteinogenics = new AminoAcid[20]; #region Create proteinogenics { IChemFile list = new ChemFile(); using (var reader = new CMLReader(ResourceLoader.GetAsStream("NCDK.Templates.Data.list_aminoacids.cml"))) { try { list = (IChemFile)reader.Read(list); var containersList = ChemFileManipulator.GetAllAtomContainers(list); int counter = 0; foreach (var ac in containersList) { Debug.WriteLine($"Adding AA: {ac}"); // convert into an AminoAcid var aminoAcid = new AminoAcid(); foreach (var next in ac.GetProperties().Keys) { Debug.WriteLine("Prop: " + next.ToString()); if (next is DictRef dictRef) { // Debug.WriteLine("DictRef type: " + dictRef.Type}"); if (string.Equals(dictRef.Type, "pdb:residueName", StringComparison.Ordinal)) { aminoAcid.SetProperty(ResidueNameKey, ac.GetProperty <string>(next).ToUpperInvariant()); aminoAcid.MonomerName = ac.GetProperty <string>(next); } else if (string.Equals(dictRef.Type, "pdb:oneLetterCode", StringComparison.Ordinal)) { aminoAcid.SetProperty(ResidueNameShortKey, ac.GetProperty <string>(next)); } else if (string.Equals(dictRef.Type, "pdb:id", StringComparison.Ordinal)) { aminoAcid.SetProperty(IdKey, ac.GetProperty <string>(next)); Debug.WriteLine($"Set AA ID to: {ac.GetProperty<string>(next)}"); } else { Trace.TraceError("Cannot deal with dictRef!"); } } } foreach (var atom in ac.Atoms) { string dictRef = atom.GetProperty <string>("org.openscience.cdk.dict"); switch (dictRef) { case "pdb:nTerminus": aminoAcid.AddNTerminus(atom); break; case "pdb:cTerminus": aminoAcid.AddCTerminus(atom); break; default: aminoAcid.Atoms.Add(atom); break; } } foreach (var bond in ac.Bonds) { aminoAcid.Bonds.Add(bond); } AminoAcidManipulator.RemoveAcidicOxygen(aminoAcid); aminoAcid.SetProperty(NoAtomsKey, "" + aminoAcid.Atoms.Count); aminoAcid.SetProperty(NoBoundsKey, "" + aminoAcid.Bonds.Count); if (counter < proteinogenics.Length) { proteinogenics[counter] = aminoAcid; } else { Trace.TraceError("Could not store AminoAcid! Array too short!"); } counter++; } } catch (Exception exception) { if (exception is CDKException | exception is IOException) { Trace.TraceError($"Failed reading file: {exception.Message}"); Debug.WriteLine(exception); } else { throw; } } } } #endregion int count = proteinogenics.Length; singleLetterCodeMap = new Dictionary <string, IAminoAcid>(count); threeLetterCodeMap = new Dictionary <string, IAminoAcid>(count); singleLetterToThreeLetter = new Dictionary <string, string>(count); threeLetterToSingleLetter = new Dictionary <string, string>(count); foreach (IAminoAcid aa in proteinogenics) { var single = aa.GetProperty <string>(ResidueNameShortKey); var three = aa.GetProperty <string>(ResidueNameKey); singleLetterCodeMap[single] = aa; threeLetterCodeMap[three] = aa; singleLetterToThreeLetter[single] = three; threeLetterToSingleLetter[three] = single; } }
/// <summary> Creates amino acid AminoAcid objects. /// /// </summary> /// <returns> aminoAcids, a HashMap containing the amino acids as AminoAcids. /// </returns> public static AminoAcid[] createAAs() { if (aminoAcids != null) { return(aminoAcids); } // Create set of AtomContainers aminoAcids = new AminoAcid[20]; IChemFile list = new ChemFile(); //UPGRADE_ISSUE: Method 'java.lang.ClassLoader.getResourceAsStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassLoader'" //UPGRADE_ISSUE: Method 'java.lang.Class.getClassLoader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassgetClassLoader'" CMLReader reader = new CMLReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + "list_aminoacids.cml"));//typeof(AminoAcids).getClassLoader().getResourceAsStream("data/templates/list_aminoacids.cml")); try { list = (IChemFile)reader.read(list); IAtomContainer[] containers = ChemFileManipulator.getAllAtomContainers(list); for (int i = 0; i < containers.Length; i++) { //logger.debug("Adding AA: ", containers[i]); // convert into an AminoAcid AminoAcid aminoAcid = new AminoAcid(); IAtom[] atoms = containers[i].Atoms; System.Collections.IEnumerator props = containers[i].Properties.Keys.GetEnumerator(); //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'" while (props.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'" System.Object next = props.Current; //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" //logger.debug("Prop class: " + next.GetType().FullName); //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" //logger.debug("Prop: " + next.ToString()); if (next is DictRef) { DictRef dictRef = (DictRef)next; // System.out.println("DictRef type: " + dictRef.getType()); if (dictRef.Type.Equals("pdb:residueName")) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" aminoAcid.setProperty(RESIDUE_NAME, containers[i].getProperty(dictRef).ToString().ToUpper()); } else if (dictRef.Type.Equals("pdb:oneLetterCode")) { aminoAcid.setProperty(RESIDUE_NAME_SHORT, containers[i].getProperty(dictRef)); } else if (dictRef.Type.Equals("pdb:id")) { aminoAcid.setProperty(ID, containers[i].getProperty(dictRef)); //logger.debug("Set AA ID to: ", containers[i].getProperty(dictRef)); } else { //logger.error("Cannot deal with dictRef!"); } } } for (int atomCount = 0; atomCount < atoms.Length; atomCount++) { IAtom atom = atoms[atomCount]; System.String dictRef = (System.String)atom.getProperty("org.openscience.cdk.dict"); if (dictRef != null && dictRef.Equals("pdb:nTerminus")) { aminoAcid.addNTerminus(atom); } else if (dictRef != null && dictRef.Equals("pdb:cTerminus")) { aminoAcid.addCTerminus(atom); } else { aminoAcid.addAtom(atom); } } IBond[] bonds = containers[i].Bonds; for (int bondCount = 0; bondCount < bonds.Length; bondCount++) { aminoAcid.addBond(bonds[bondCount]); } AminoAcidManipulator.removeAcidicOxygen(aminoAcid); aminoAcid.setProperty(NO_ATOMS, "" + aminoAcid.AtomCount); aminoAcid.setProperty(NO_BONDS, "" + aminoAcid.getBondCount()); if (i < aminoAcids.Length) { aminoAcids[i] = aminoAcid; } else { //logger.error("Could not store AminoAcid! Array too short!"); } } } catch (System.Exception exception) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" //logger.error("Failed reading file: ", exception.Message); //logger.debug(exception); } return(aminoAcids); }