/// <summary> Reads the atom types from the CDK based atom type list. /// /// </summary> /// <param name="builder">IChemObjectBuilder used to construct the IAtomType's. /// </param> /// <throws> IOException when a problem occured with reading from the InputStream </throws> /// <returns> A Vector with read IAtomType's. /// </returns> public virtual System.Collections.ArrayList readAtomTypes(IChemObjectBuilder builder) { System.Collections.ArrayList atomTypes = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(0)); if (ins == null) { try { ins = Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + configFile); } catch (System.Exception exc) { //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(exc.Message); //logger.debug(exc); throw new System.IO.IOException("There was a problem getting a stream for " + configFile + " with getClass.getClassLoader.getResourceAsStream"); } if (ins == null) { try { //UPGRADE_ISSUE: Method 'java.lang.Class.getResourceAsStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassgetResourceAsStream_javalangString'" ins = Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + configFile); } catch (System.Exception exc) { //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(exc.Message); //logger.debug(exc); throw new System.IO.IOException("There was a problem getting a stream for " + configFile + " with getClass.getResourceAsStream"); } } } if (ins == null) throw new System.IO.IOException("There was a problem getting an input stream"); AtomTypeReader reader = new AtomTypeReader(new System.IO.StreamReader(ins, System.Text.Encoding.Default)); atomTypes = reader.readAtomTypes(builder); for (int f = 0; f < atomTypes.Count; f++) { System.Object object_Renamed = atomTypes[f]; if (object_Renamed == null) { System.Console.Out.WriteLine("Expecting an object but found null!"); if (!(object_Renamed is IAtomType)) { //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'" System.Console.Out.WriteLine("Expecting cdk.AtomType class, but got: " + object_Renamed.GetType().FullName); } } } return atomTypes; }
/// <param name="builder">the ChemObjectBuilder implementation used to construct the AtomType's. /// </param> protected internal virtual AtomTypeFactory getAtomTypeFactory(IChemObjectBuilder builder) { if (structgenATF == null) { try { structgenATF = AtomTypeFactory.getInstance("org/openscience/cdk/config/data/structgen_atomtypes.xml", builder); } catch (System.Exception exception) { //logger.debug(exception); throw new CDKException("Could not instantiate AtomTypeFactory!", exception); } } return structgenATF; }
/// <param name="builder">the ChemObjectBuilder implementation used to construct the AtomType's. /// </param> protected internal virtual AtomTypeFactory getAtomTypeFactory(IChemObjectBuilder builder) { if (structgenATF == null) { try { structgenATF = AtomTypeFactory.getInstance(atomTypeList, builder); } catch (System.Exception exception) { //logger.debug(exception); throw new CDKException("Could not instantiate AtomTypeFactory!", exception); } } return structgenATF; }
/// <summary> Constructs an IsotopeHandler used by the IsotopeReader. /// /// </summary> /// <param name="builder">The IChemObjectBuilder used to create new IIsotope's. /// </param> public IsotopeHandler(IChemObjectBuilder builder) { //logger = new LoggingTool(this); this.builder = builder; }
//private IChemObjectBuilder builder; /// <summary> Default constructor</summary> public SmilesGenerator(IChemObjectBuilder builder) { //this.builder = builder; try { isotopeFactory = IsotopeFactory.getInstance(builder); } catch (System.IO.IOException e) { SupportClass.WriteStackTrace(e, Console.Error); } //UPGRADE_NOTE: Exception 'java.lang.ClassNotFoundException' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'" catch (System.Exception e) { //UPGRADE_ISSUE: Method 'java.lang.ClassNotFoundException.printStackTrace' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassNotFoundExceptionprintStackTrace'" //e.printStackTrace(); } }
/// <summary> Returns an IsotopeFactory instance. /// /// </summary> /// <param name="builder"> ChemObjectBuilder used to construct the Isotope's /// </param> /// <returns> The instance value /// </returns> /// <exception cref="IOException"> Description of the Exception /// </exception> /// <exception cref="OptionalDataException"> Description of the Exception /// </exception> /// <exception cref="ClassNotFoundException"> Description of the Exception /// </exception> public static IsotopeFactory getInstance(IChemObjectBuilder builder) { if (ifac == null) { ifac = new IsotopeFactory(builder); } return ifac; }
/// <summary> Reads the atom types from the data file. /// /// </summary> /// <param name="builder">The IChemObjectBuilder used to create new IAtomType's. /// </param> /// <returns> a Vector with atom types. Is empty if some reading error occured. /// </returns> public virtual System.Collections.ArrayList readAtomTypes(IChemObjectBuilder builder) { System.Collections.ArrayList isotopes = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); try { parser.setFeature("http://xml.org/sax/features/validation", false); //logger.info("Deactivated validation"); } //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" catch (System.Xml.XmlException exception) { //logger.warn("Cannot deactivate validation: ", exception.Message); //logger.debug(exception); } AtomTypeHandler handler = new AtomTypeHandler(builder); parser.setContentHandler(handler); try { parser.parse(new XmlSourceSupport(input)); isotopes = handler.AtomTypes; } catch (System.IO.IOException 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("IOException: ", exception.Message); //logger.debug(exception); } //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" catch (System.Xml.XmlException saxe) { //logger.error("SAXException: ", saxe.Message); //logger.debug(saxe); } return isotopes; }
public virtual IAtomContainer readConnectionTable(IChemObjectBuilder builder) { IAtomContainer readData = builder.newAtomContainer(); bool foundEND = false; while (Ready && !foundEND) { System.String command = readCommand(); if ("END CTAB".Equals(command)) { foundEND = true; } else if ("BEGIN CTAB".Equals(command)) { // that's fine } else if ("COUNTS".Equals(command)) { // don't think I need to parse this } else if ("BEGIN ATOM".Equals(command)) { readAtomBlock(readData); } else if ("BEGIN BOND".Equals(command)) { readBondBlock(readData); } else if ("BEGIN SGROUP".Equals(command)) { readSGroup(readData); } else { //logger.warn("Unrecognized command: " + command); } } return readData; }
public void SetUp() { builder = ChemObjectBuilder.Instance; }
/// <summary> Method to create a default AtomTypeFactory, using the given InputStream. /// An AtomType of this kind is not cached. /// /// </summary> /// <seealso cref="getInstance(String, IChemObjectBuilder)"> /// </seealso> /// <param name="ins"> InputStream containing the data /// </param> /// <param name="format"> String representing the possible formats ('xml' and 'txt') /// </param> /// <param name="builder"> IChemObjectBuilder used to make IChemObject instances /// </param> /// <returns> The AtomTypeFactory for the given data file /// </returns> /// <throws> IOException when the file cannot be read </throws> /// <throws> ClassNotFoundException when the AtomTypeFactory cannot be found </throws> public static AtomTypeFactory getInstance(System.IO.Stream ins, System.String format, IChemObjectBuilder builder) { return new AtomTypeFactory(ins, format, builder); }
private void readConfiguration(System.IO.Stream ins, System.String format, IChemObjectBuilder builder) { IAtomTypeConfigurator atc = constructConfigurator(format); if (atc != null) { atc.InputStream = ins; try { atomTypes = atc.readAtomTypes(builder); } catch (System.Exception exc) { //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("Could not read AtomType's from file due to: ", exc.Message); //logger.debug(exc); } } else { //logger.debug("AtomTypeConfigurator was null!"); atomTypes = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); } }
/// <summary> /// Creates a new instance. /// </summary> /// <param name="symbol">the atom symbol</param> /// <param name="builder"></param> public AliphaticSymbolAtom(string symbol, IChemObjectBuilder builder) : base(builder) { IsAromatic = true; Symbol = symbol; }
/// <summary> Read the config from a text file. /// /// </summary> /// <param name="configFile"> name of the config file /// </param> /// <param name="builder"> IChemObjectBuilder used to make IChemObject instances /// </param> private void readConfiguration(System.String fileName, IChemObjectBuilder builder) { //logger.info("Reading config file from ", fileName); System.IO.Stream ins = null; { //try to see if this is a resource //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'" ins = Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + fileName); if (ins == null) { // try to see if this configFile is an actual file System.IO.FileInfo file = new System.IO.FileInfo(fileName); bool tmpBool; if (System.IO.File.Exists(file.FullName)) tmpBool = true; else tmpBool = System.IO.Directory.Exists(file.FullName); if (tmpBool) { //logger.debug("configFile is a File"); // what's next? try { //UPGRADE_TODO: Constructor 'java.io.FileInputStream.FileInputStream' was converted to 'System.IO.FileStream.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileInputStreamFileInputStream_javaioFile'" ins = new System.IO.FileStream(file.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read); } 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(exception.Message); //logger.debug(exception); } } else { //logger.error("no stream and no file"); } } } System.String format = XML_EXTENSION; if (fileName.EndsWith(TXT_EXTENSION)) { format = TXT_EXTENSION; } else if (fileName.EndsWith(XML_EXTENSION)) { format = XML_EXTENSION; } readConfiguration(ins, format, builder); }
/// <summary> Method to create a specialized AtomTypeFactory. Available lists in CDK are: /// <ul> /// <li>org/openscience/cdk/config/data/jmol_atomtypes.txt /// <li>org/openscience/cdk/config/data/mol2_atomtypes.xml /// <li>org/openscience/cdk/config/data/structgen_atomtypes.xml /// <li>org/openscience/cdk/config/data/valency_atomtypes.xml /// <li>org/openscience/cdk/config/data/mm2_atomtypes.xml /// <li>org/openscience/cdk/config/data/mmff94_atomtypes.xml /// </ul> /// /// </summary> /// <param name="configFile"> String the name of the data file /// </param> /// <param name="builder"> IChemObjectBuilder used to make IChemObject instances /// </param> /// <returns> The AtomTypeFactory for the given data file /// </returns> /// <throws> IOException when the file cannot be read </throws> /// <throws> ClassNotFoundException when the AtomTypeFactory cannot be found </throws> public static AtomTypeFactory getInstance(System.String configFile, IChemObjectBuilder builder) { if (tables == null) { tables = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable()); } if (!(tables.ContainsKey(configFile))) { tables[configFile] = new AtomTypeFactory(configFile, builder); } return (AtomTypeFactory)tables[configFile]; }
/// <summary> Method to create a default AtomTypeFactory, using the structgen atom type list. /// /// </summary> /// <seealso cref="getInstance(String, IChemObjectBuilder)"> /// </seealso> /// <param name="builder"> IChemObjectBuilder used to make IChemObject instances /// </param> /// <returns> The AtomTypeFactory for the given data file /// </returns> /// <throws> IOException when the file cannot be read </throws> /// <throws> ClassNotFoundException when the AtomTypeFactory cannot be found </throws> public static AtomTypeFactory getInstance(IChemObjectBuilder builder) { return getInstance("structgen_atomtypes.xml", builder); }
/// <summary> /// Creates a new instance /// </summary> public AromaticAtom(IChemObjectBuilder builder) : base(builder) { IsAromatic = true; }
/// <summary> /// Initiate the MolecularFormulaGenerator. /// </summary> /// <param name="minMass">Lower boundary of the target mass range</param> /// <param name="maxMass">Upper boundary of the target mass range</param> /// <param name="mfRange">A range of elemental compositions defining the search space</param> /// <exception cref="ArgumentOutOfRangeException">In case some of the isotopes in mfRange has undefined exact mass or in case illegal parameters are provided (e.g., negative mass values or empty MolecularFormulaRange)</exception> /// <seealso cref="MolecularFormulaRange"/> public FullEnumerationFormulaGenerator(IChemObjectBuilder builder, double minMass, double maxMass, MolecularFormulaRange mfRange) { Trace.TraceInformation("Initiate MolecularFormulaGenerator, mass range " + minMass + "-" + maxMass); // Check parameter values if (minMass < 0.0) { throw (new ArgumentOutOfRangeException(nameof(minMass), "The minimum and maximum mass values must be >=0")); } if (maxMass < 0.0) { throw (new ArgumentOutOfRangeException(nameof(maxMass), "The minimum and maximum mass values must be >=0")); } if ((minMass > maxMass)) { throw (new ArgumentException("Minimum mass must be <= maximum mass")); } if ((mfRange == null) || (mfRange.GetIsotopes().Count() == 0)) { throw (new ArgumentException("The MolecularFormulaRange parameter must be non-null and must contain at least one isotope")); } // Save the parameters this.builder = builder; this.minMass = minMass; this.maxMass = maxMass; // Sort the elements by mass in ascending order. That speeds up // the search. var isotopesSet = new SortedSet <IIsotope>( new IIsotopeSorterByMass()); foreach (IIsotope isotope in mfRange.GetIsotopes()) { // Check if exact mass of each isotope is set if (isotope.ExactMass == null) { throw new ArgumentException($"The exact mass value of isotope {isotope} is not set"); } isotopesSet.Add(isotope); } isotopes = isotopesSet.ToArray(); // Save the element counts from the provided MolecularFormulaRange minCounts = new int[isotopes.Length]; maxCounts = new int[isotopes.Length]; for (int i = 0; i < isotopes.Length; i++) { minCounts[i] = mfRange.GetIsotopeCountMin(isotopes[i]); maxCounts[i] = mfRange.GetIsotopeCountMax(isotopes[i]); // Update the maximum count according to the mass limit int maxCountAccordingToMass = (int)Math.Floor(maxMass / isotopes[i].ExactMass.Value); if (maxCounts[i] > maxCountAccordingToMass) { maxCounts[i] = maxCountAccordingToMass; } } // Set the current counters to minimal values, initially currentCounts = Arrays.CopyOf(minCounts, minCounts.Length); }
private IReaction ReadReaction(IChemObjectBuilder builder) { IReaction reaction = builder.NewReaction(); ReadLine(); // first line should be $RXN ReadLine(); // second line ReadLine(); // third line ReadLine(); // fourth line int reactantCount = 0; int productCount = 0; bool foundCOUNTS = false; while (!foundCOUNTS) { string command = ReadCommand(); if (command.StartsWith("COUNTS", StringComparison.Ordinal)) { var tokenizer = Strings.Tokenize(command); try { reactantCount = int.Parse(tokenizer[1], NumberFormatInfo.InvariantInfo); Trace.TraceInformation($"Expecting {reactantCount} reactants in file"); productCount = int.Parse(tokenizer[2], NumberFormatInfo.InvariantInfo); Trace.TraceInformation($"Expecting {productCount } products in file"); } catch (Exception exception) { Debug.WriteLine(exception); throw new CDKException("Error while counts line of RXN file", exception); } foundCOUNTS = true; } else { Trace.TraceWarning("Waiting for COUNTS line, but found: " + command); } } // now read the reactants for (int i = 1; i <= reactantCount; i++) { var molFile = new StringBuilder(); string announceMDLFileLine = ReadCommand(); if (!string.Equals(announceMDLFileLine, "BEGIN REACTANT", StringComparison.Ordinal)) { string error = "Excepted start of reactant, but found: " + announceMDLFileLine; Trace.TraceError(error); throw new CDKException(error); } string molFileLine = ""; while (!molFileLine.EndsWith("END REACTANT", StringComparison.Ordinal)) { molFileLine = ReadLine(); molFile.Append(molFileLine); molFile.Append('\n'); } ; try { // read MDL molfile content MDLV3000Reader reader = new MDLV3000Reader(new StringReader(molFile.ToString()), base.ReaderMode); IAtomContainer reactant = (IAtomContainer)reader.Read(builder.NewAtomContainer()); reader.Close(); // add reactant reaction.Reactants.Add(reactant); } catch (Exception exception) { if (!(exception is ArgumentException || exception is CDKException || exception is IOException)) { throw; } string error = "Error while reading reactant: " + exception.Message; Trace.TraceError(error); Debug.WriteLine(exception); throw new CDKException(error, exception); } } // now read the products for (int i = 1; i <= productCount; i++) { var molFile = new StringBuilder(); string announceMDLFileLine = ReadCommand(); if (!string.Equals(announceMDLFileLine, "BEGIN PRODUCT", StringComparison.Ordinal)) { string error = "Excepted start of product, but found: " + announceMDLFileLine; Trace.TraceError(error); throw new CDKException(error); } string molFileLine = ""; while (!molFileLine.EndsWith("END PRODUCT", StringComparison.Ordinal)) { molFileLine = ReadLine(); molFile.Append(molFileLine); molFile.Append('\n'); } ; try { // read MDL molfile content MDLV3000Reader reader = new MDLV3000Reader(new StringReader(molFile.ToString())); IAtomContainer product = (IAtomContainer)reader.Read(builder.NewAtomContainer()); reader.Close(); // add product reaction.Products.Add(product); } catch (Exception exception) { if (!(exception is ArgumentException || exception is CDKException || exception is IOException)) { throw; } string error = "Error while reading product: " + exception.Message; Trace.TraceError(error); Debug.WriteLine(exception); throw new CDKException(error, exception); } } return(reaction); }
/// <summary> Private constructor for the AtomTypeFactory singleton. /// /// </summary> /// <exception cref="IOException"> Thrown if something goes wrong with reading the config /// </exception> /// <exception cref="ClassNotFoundException"> Thrown if a class was not found :-) /// </exception> private AtomTypeFactory(System.IO.Stream ins, System.String format, IChemObjectBuilder builder) { //if (//logger == null) //{ // //logger = new LoggingTool(this); //} atomTypes = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(100)); readConfiguration(ins, format, builder); }
/// <summary> /// Creates a new instance. /// </summary> /// <param name="atomicNumber"></param> public AtomicNumberAtom(int atomicNumber, IChemObjectBuilder builder) : base(builder) { this.AtomicNumber = atomicNumber; }
/// <summary> /// Constructs a new EnumerablePCCompoundXLReader that can read Molecule from a given Stream and IChemObjectBuilder. /// </summary> /// <param name="ins">The input stream</param> /// <param name="builder">The builder</param> /// <exception cref="Exception">if there is a problem creating a <see cref="StreamReader"/></exception> public EnumerablePCCompoundXMLReader(Stream ins, IChemObjectBuilder builder) : this(new StreamReader(ins), builder) { }
/// <summary> Read a Reaction from a file in MDL RXN format /// /// </summary> /// <returns> The Reaction that was read from the MDL file. /// </returns> private IReaction readReaction(IChemObjectBuilder builder) { IReaction reaction = builder.newReaction(); try { input.ReadLine(); // first line should be $RXN input.ReadLine(); // second line input.ReadLine(); // third line input.ReadLine(); // fourth line } catch (System.IO.IOException exception) { //logger.debug(exception); throw new CDKException("Error while reading header of RXN file", exception); } int reactantCount = 0; int productCount = 0; try { System.String countsLine = input.ReadLine(); /* this line contains the number of reactants and products */ SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(countsLine); reactantCount = System.Int32.Parse(tokenizer.NextToken()); //logger.info("Expecting " + reactantCount + " reactants in file"); productCount = System.Int32.Parse(tokenizer.NextToken()); //logger.info("Expecting " + productCount + " products in file"); } catch (System.Exception exception) { //logger.debug(exception); throw new CDKException("Error while counts line of RXN file", exception); } // now read the reactants try { for (int i = 1; i <= reactantCount; i++) { System.Text.StringBuilder molFile = new System.Text.StringBuilder(); input.ReadLine(); // announceMDLFileLine System.String molFileLine = ""; do { molFileLine = input.ReadLine(); molFile.Append(molFileLine); molFile.Append("\n"); } while (!molFileLine.Equals("M END")); // read MDL molfile content MDLReader reader = new MDLReader(new StreamReader(molFile.ToString())); IMolecule reactant = (IMolecule)reader.read(builder.newMolecule()); // add reactant reaction.addReactant(reactant); } } catch (CDKException exception) { // rethrow exception from MDLReader throw exception; } catch (System.Exception exception) { //logger.debug(exception); throw new CDKException("Error while reading reactant", exception); } // now read the products try { for (int i = 1; i <= productCount; i++) { System.Text.StringBuilder molFile = new System.Text.StringBuilder(); input.ReadLine(); // String announceMDLFileLine = System.String molFileLine = ""; do { molFileLine = input.ReadLine(); molFile.Append(molFileLine); molFile.Append("\n"); } while (!molFileLine.Equals("M END")); // read MDL molfile content MDLReader reader = new MDLReader(new StreamReader(molFile.ToString())); IMolecule product = (IMolecule)reader.read(builder.newMolecule()); // add reactant reaction.addProduct(product); } } catch (CDKException exception) { // rethrow exception from MDLReader throw exception; } catch (System.Exception exception) { //logger.debug(exception); throw new CDKException("Error while reading products", exception); } // now try to map things, if wanted //logger.info("Reading atom-atom mapping from file"); // distribute all atoms over two AtomContainer's IAtomContainer reactingSide = builder.newAtomContainer(); IMolecule[] molecules = reaction.Reactants.Molecules; for (int i = 0; i < molecules.Length; i++) { reactingSide.add(molecules[i]); } IAtomContainer producedSide = builder.newAtomContainer(); molecules = reaction.Products.Molecules; for (int i = 0; i < molecules.Length; i++) { producedSide.add(molecules[i]); } // map the atoms int mappingCount = 0; IAtom[] reactantAtoms = reactingSide.Atoms; IAtom[] producedAtoms = producedSide.Atoms; for (int i = 0; i < reactantAtoms.Length; i++) { for (int j = 0; j < producedAtoms.Length; j++) { if (reactantAtoms[i].ID != null && reactantAtoms[i].ID.Equals(producedAtoms[j].ID)) { reaction.addMapping(builder.newMapping(reactantAtoms[i], producedAtoms[j])); mappingCount++; break; } } } //logger.info("Mapped atom pairs: " + mappingCount); return reaction; }
/// <summary> /// Build fingerprint /// </summary> /// <param name="mol"></param> public static BitSetFingerprint BuildBitSetFingerprint( IAtomContainer mol, FingerprintType fpType, int fpSubtype = -1, int fpLen = -1) { // Data for Tanimoto similarity using various fingerprint types for CorpId 123456 query. // Cart - Standard MDL Oracle Cartridge scores // // Similarity Score // ------------------------------------------------ // Size -> 192 896 1024 1024 128 1024 320 // CorpId Cart MACCS PbChm ECFP4 EXT EState Basic Sbstr // ------ ---- ---- ---- ---- ---- ---- ---- ---- // 123456 0.99 1.00 1.00 1.00 1.00 1.00 1.00 1.00 // 123456 0.99 0.98 0.96 0.77 0.95 1.00 0.95 1.00 // 123456 0.99 0.98 0.96 0.77 0.95 1.00 0.94 1.00 // 123456 0.99 1.00 1.00 1.00 1.00 1.00 1.00 1.00 // 123456 0.99 1.00 1.00 1.00 1.00 1.00 1.00 1.00 // 123456 0.99 0.91 1.00 0.81 1.00 1.00 1.00 1.00 // 123456 0.98 0.95 1.00 0.74 0.92 1.00 0.93 0.94 // 123456 0.98 1.00 1.00 1.00 1.00 1.00 1.00 1.00 // 123456 0.98 1.00 1.00 1.00 1.00 1.00 1.00 1.00 // 123456 0.98 1.00 0.83 0.76 0.77 0.90 0.76 0.94 // LSH Bin Count - The number of LSH bins (of 25) that match the query bin values //-------------- // CorpId MAC PbC ECFP EX // ------ --- --- --- --- // 123456 25 25 25 25 // 123456 25 20 7 16 // 123456 25 20 9 19 // 123456 25 25 25 25 // 123456 25 25 25 25 // 123456 20 25 9 25 // 123456 21 25 11 17 // 123456 25 25 25 25 // 123456 25 25 25 25 // 123456 25 9 6 11 // Data for Tanimoto similarity using various Circular fingerprint types. // Using 2 molecules where the 2nd just has an added methyl group. // // Measure Score // -------- ----- // ECFP0 1.00 // ECFP2 .88 // ECFP4 .75 // ECFP6 .64 // FCFP0 1.00 // FCFP2 .92 // FCFP4 .84 // FCFP6 .74 IFingerprinter ifptr = null; IBitFingerprint ibfp = null; BitSetFingerprint bfp = null; BitSet bs; IAtomContainer mol2; string s = ""; DateTime t0 = DateTime.Now; double getFptrTime = 0, buildFpTime = 0; if (fpType == FingerprintType.Basic) // size = 1024 { ifptr = new Fingerprinter(); } else if (fpType == FingerprintType.Circular) // size variable { int cfpClass = fpSubtype; if (cfpClass < CircularFingerprinter.CLASS_ECFP0 || cfpClass > CircularFingerprinter.CLASS_ECFP6) { cfpClass = CircularFingerprintType.DefaultCircularClass; // default class } if (fpLen < 0) { fpLen = CircularFingerprintType.DefaultCircularLength; // default length } ifptr = new CircularFingerprinter(cfpClass, fpLen); //CircularFingerprinter cfp = (CircularFingerprinter)ifptr; //ICountFingerprint cntFp = cfp.getCountFingerprint(mol); // debug //s = CircularFpToString(cfp); // debug } else if (fpType == FingerprintType.Extended) // size = 1024 { ifptr = new ExtendedFingerprinter(); // use DEFAULT_SIZE and DEFAULT_SEARCH_DEPTH } else if (fpType == FingerprintType.EState) // size = 128 { ifptr = new EStateFingerprinter(); // use DEFAULT_SIZE and DEFAULT_SEARCH_DEPTH } else if (fpType == FingerprintType.MACCS) // size = 192 { if (MACCSFp == null) { MACCSFp = new MACCSFingerprinter(); } ifptr = MACCSFp; } else if (fpType == FingerprintType.PubChem) // size = 896 { IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance(); ifptr = new PubchemFingerprinter(builder); } else if (fpType == FingerprintType.ShortestPath) // size = { ifptr = new ShortestPathFingerprinter(); // fails with atom type issue for many structures (e.g. 123456) } else if (fpType == FingerprintType.Signature) // size = { ifptr = new SignatureFingerprinter(); // can't convert array fingerprint to bitsetfingerprint } else if (fpType == FingerprintType.Substructure) // size = 320 { ifptr = new SubstructureFingerprinter(); } else { throw new Exception("Invalid CdkFingerprintType: " + fpType); } getFptrTime = TimeOfDay.Delta(ref t0); ibfp = ifptr.getBitFingerprint(mol); bfp = (BitSetFingerprint)ibfp; buildFpTime = TimeOfDay.Delta(ref t0); //long size = bfp.size(); //int card = bfp.cardinality(); return(bfp); }
public virtual IMolecule readMolecule(IChemObjectBuilder builder) { return builder.newMolecule(readConnectionTable(builder)); }
public TotalHCountAtom(int totalHCount, IChemObjectBuilder builder) : base(builder) { this.totalHCount = totalHCount; }
/// <summary> Reads a text based configuration file. /// /// </summary> /// <param name="builder">IChemObjectBuilder used to construct the IAtomType's. /// </param> /// <throws> IOException when a problem occured with reading from the InputStream </throws> /// <returns> A Vector with read IAtomType's. /// </returns> public virtual System.Collections.ArrayList readAtomTypes(IChemObjectBuilder builder) { System.Collections.ArrayList atomTypes = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); if (ins == null) { // trying the default //System.out.println("readAtomTypes getResourceAsStream:" // + configFile); //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'" ins = Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + configFile); } if (ins == null) throw new System.IO.IOException("There was a problem getting the default stream: " + configFile); // read the contents from file //UPGRADE_TODO: The differences in the expected value of parameters for constructor 'java.io.BufferedReader.BufferedReader' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" //UPGRADE_WARNING: At least one expression was used more than once in the target code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1181'" System.IO.StreamReader reader = new System.IO.StreamReader(new System.IO.StreamReader(ins, System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(ins, System.Text.Encoding.Default).CurrentEncoding, false, 1024); SupportClass.Tokenizer tokenizer; System.String string_Renamed; while (true) { string_Renamed = reader.ReadLine(); if (string_Renamed == null) { break; } if (!string_Renamed.StartsWith("#")) { System.String name = ""; System.String rootType = ""; int atomicNumber = 0, colorR = 0, colorG = 0, colorB = 0; double mass = 0.0, vdwaals = 0.0, covalent = 0.0; tokenizer = new SupportClass.Tokenizer(string_Renamed, "\t ,;"); int tokenCount = tokenizer.Count; if (tokenCount == 9) { name = tokenizer.NextToken(); rootType = tokenizer.NextToken(); System.String san = tokenizer.NextToken(); System.String sam = tokenizer.NextToken(); System.String svdwaals = tokenizer.NextToken(); System.String scovalent = tokenizer.NextToken(); System.String sColorR = tokenizer.NextToken(); System.String sColorG = tokenizer.NextToken(); System.String sColorB = tokenizer.NextToken(); try { //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" mass = System.Double.Parse(sam); //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" vdwaals = System.Double.Parse(svdwaals); //UPGRADE_TODO: The differences in the format of parameters for constructor 'java.lang.Double.Double' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" covalent = System.Double.Parse(scovalent); atomicNumber = System.Int32.Parse(san); colorR = System.Int32.Parse(sColorR); colorG = System.Int32.Parse(sColorG); colorB = System.Int32.Parse(sColorB); } catch (System.FormatException nfe) { throw new System.IO.IOException("AtomTypeTable.ReadAtypes: " + "Malformed Number"); } IAtomType atomType = builder.newAtomType(name, rootType); atomType.AtomicNumber = atomicNumber; atomType.setExactMass(mass); atomType.VanderwaalsRadius = vdwaals; atomType.CovalentRadius = covalent; System.Drawing.Color color = System.Drawing.Color.FromArgb(colorR, colorG, colorB); atomType.setProperty("org.openscience.cdk.renderer.color", color); atomTypes.Add(atomType); } else { throw new System.IO.IOException("AtomTypeTable.ReadAtypes: " + "Wrong Number of fields"); } } } // end while ins.Close(); return atomTypes; }
/// <summary> /// Constructs an empty query bond. /// </summary> public QueryBond(IChemObjectBuilder builder) { this.builder = builder; }
/// <summary> /// Constructs a query bond with a single query bond order.. /// </summary> /// <param name="atom1">the first Atom in the query bond</param> /// <param name="atom2">the second Atom in the query bond</param> /// <param name="order"></param> /// <param name="builder"></param> public QueryBond(IAtom atom1, IAtom atom2, BondOrder order, IChemObjectBuilder builder) : base(atom1, atom2, order) { this.builder = builder; }
/// <summary> /// Constructs a multi-center query bond, with undefined order and no stereo information. /// </summary> /// <param name="atoms">An array of IAtom containing the atoms constituting the query bond</param> public QueryBond(IAtom[] atoms, IChemObjectBuilder builder) { this.builder = builder; SetAtoms(atoms); }
//private LoggingTool //logger; /// <summary> Private constructor for the IsotopeFactory object. /// /// </summary> /// <exception cref="IOException"> A problem with reading the isotopes.xml /// file /// </exception> /// <exception cref="OptionalDataException"> Unexpected data appeared in the isotope /// ObjectInputStream /// </exception> /// <exception cref="ClassNotFoundException"> A problem instantiating the isotopes /// </exception> private IsotopeFactory(IChemObjectBuilder builder) { //logger = new LoggingTool(this); //logger.info("Creating new IsotopeFactory"); System.IO.Stream ins = null; // ObjIn in = null; System.String errorMessage = "There was a problem getting org.openscience.cdk." + "config.isotopes.xml as a stream"; try { System.String configFile = "isotopes.xml"; //if (debug) //logger.debug("Getting stream for ", configFile); //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'" ins = Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + configFile); //this.GetType().getClassLoader().getResourceAsStream(configFile); } catch (System.Exception exception) { //logger.error(errorMessage); //logger.debug(exception); throw new System.IO.IOException(errorMessage); } if (ins == null) { //logger.error(errorMessage); throw new System.IO.IOException(errorMessage); } IsotopeReader reader = new IsotopeReader(ins, builder); //in = new ObjIn(ins, new Config().aliasID(false)); //isotopes = (Vector) in.readObject(); isotopes = reader.readIsotopes(); //if (debug) //logger.debug("Found #isotopes in file: ", isotopes.Count); /* for (int f = 0; f < isotopes.size(); f++) { Isotope isotope = (Isotope)isotopes.elementAt(f); } What's this loop for?? */ majorIsotopes = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable()); }
/// <summary> /// Constructs a multi-center query bond, with a specified order and no stereo information. /// </summary> /// <param name="atoms">An array of IAtom containing the atoms constituting the query bond</param> /// <param name="order">The order of the query bond</param> public QueryBond(IAtom[] atoms, BondOrder order, IChemObjectBuilder builder) { this.builder = builder; SetAtoms(atoms); this.order = order; }
public Convertor(IChemObjectBuilder builder) { this.builder = builder; }
/// <summary> /// Constructs a query bond with a given order and stereo orientation from an array of atoms. /// </summary> /// <param name="atom1">the first Atom in the query bond</param> /// <param name="atom2">the second Atom in the query bond</param> /// <param name="order">the query bond order</param> /// <param name="stereo">a descriptor the stereochemical orientation of this query bond</param> public QueryBond(IAtom atom1, IAtom atom2, BondOrder order, BondStereo stereo, IChemObjectBuilder builder) { this.builder = builder; SetAtoms(new[] { atom1, atom2 }); this.order = order; this.stereo = stereo; }
/// <summary> Constructs a new AtomTypeHandler and will create IAtomType /// implementations using the given IChemObjectBuilder. /// /// </summary> /// <param name="build">The IChemObjectBuilder used to create the IAtomType's. /// </param> public AtomTypeHandler(IChemObjectBuilder build) { //logger = new LoggingTool(this); builder = build; }
private IReaction readReaction(IChemObjectBuilder builder) { IReaction reaction = builder.newReaction(); readLine(); // first line should be $RXN readLine(); // second line readLine(); // third line readLine(); // fourth line int reactantCount = 0; int productCount = 0; bool foundCOUNTS = false; while (Ready && !foundCOUNTS) { System.String command = readCommand(); if (command.StartsWith("COUNTS")) { SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(command); try { tokenizer.NextToken(); reactantCount = System.Int32.Parse(tokenizer.NextToken()); //logger.info("Expecting " + reactantCount + " reactants in file"); productCount = System.Int32.Parse(tokenizer.NextToken()); //logger.info("Expecting " + productCount + " products in file"); } catch (System.Exception exception) { //logger.debug(exception); throw new CDKException("Error while counts line of RXN file", exception); } foundCOUNTS = true; } else { //logger.warn("Waiting for COUNTS line, but found: " + command); } } // now read the reactants for (int i = 1; i <= reactantCount; i++) { System.Text.StringBuilder molFile = new System.Text.StringBuilder(); System.String announceMDLFileLine = readCommand(); if (!announceMDLFileLine.Equals("BEGIN REACTANT")) { System.String error = "Excepted start of reactant, but found: " + announceMDLFileLine; //logger.error(error); throw new CDKException(error); } System.String molFileLine = ""; while (!molFileLine.EndsWith("END REACTANT")) { molFileLine = readLine(); molFile.Append(molFileLine); molFile.Append("\n"); }; try { // read MDL molfile content MDLV3000Reader reader = new MDLV3000Reader(new StreamReader(molFile.ToString())); IMolecule reactant = (IMolecule)reader.read(builder.newMolecule()); // add reactant reaction.addReactant(reactant); } 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'" System.String error = "Error while reading reactant: " + exception.Message; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } } // now read the products for (int i = 1; i <= productCount; i++) { System.Text.StringBuilder molFile = new System.Text.StringBuilder(); System.String announceMDLFileLine = readCommand(); if (!announceMDLFileLine.Equals("BEGIN PRODUCT")) { System.String error = "Excepted start of product, but found: " + announceMDLFileLine; //logger.error(error); throw new CDKException(error); } System.String molFileLine = ""; while (!molFileLine.EndsWith("END PRODUCT")) { molFileLine = readLine(); molFile.Append(molFileLine); molFile.Append("\n"); }; try { // read MDL molfile content MDLV3000Reader reader = new MDLV3000Reader(new StreamReader(molFile.ToString())); IMolecule product = (IMolecule)reader.read(builder.newMolecule()); // add product reaction.addProduct(product); } 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'" System.String error = "Error while reading product: " + exception.Message; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } } return reaction; }