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); }
/// <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); }
private bool createBondsWithRebondTool(IBioPolymer pol) { RebondTool tool = new RebondTool(2.0, 0.5, 0.5); try { // configure atoms AtomTypeFactory factory = AtomTypeFactory.getInstance("jmol_atomtypes.txt", pol.Builder); IAtom[] atoms = pol.Atoms; for (int i = 0; i < atoms.Length; i++) { try { IAtomType[] types = factory.getAtomTypes(atoms[i].Symbol); if (types.Length > 0) { // just pick the first one AtomTypeManipulator.configure(atoms[i], types[0]); } else { System.Console.Out.WriteLine("Could not configure atom with symbol: " + atoms[i].Symbol); } } catch (System.Exception e) { //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.Console.Out.WriteLine("Could not configure atom (but don't care): " + e.Message); //logger.debug(e); } } tool.rebond(pol); } catch (System.Exception e) { //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 rebond the polymer: " + e.Message); //logger.debug(e); } return(true); }
/// <summary> /// Takes an object which subclasses IChemObject, e.g. Molecule, and will /// read this (from file, database, internet etc). If the specific /// implementation does not support a specific IChemObject it will throw /// an Exception. /// /// </summary> /// <param name="oObj"> The object that subclasses IChemObject /// </param> /// <returns> The IChemObject read /// </returns> /// <exception cref="CDKException"> /// /// </exception> public override IChemObject read(IChemObject oObj) { if (oObj is IChemFile) { if (pdbFactory == null) { try { pdbFactory = AtomTypeFactory.getInstance("pdb_atomtypes.xml", ((IChemFile)oObj).Builder); } catch (System.Exception exception) { //logger.debug(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'" throw new CDKException("Could not setup list of PDB atom types! " + exception.Message); } } return(readChemFile((IChemFile)oObj)); } else { throw new CDKException("Only supported is reading of ChemFile objects."); } }
/// <summary> Read a Reaction from a file in MDL RXN format /// /// </summary> /// <returns> The Reaction that was read from the MDL file. /// </returns> private IMolecule readMolecule(IMolecule molecule) { AtomTypeFactory atFactory = null; try { atFactory = AtomTypeFactory.getInstance("mol2_atomtypes.xml", molecule.Builder); } catch (System.Exception exception) { System.String error = "Could not instantiate an AtomTypeFactory"; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } try { System.String line = input.ReadLine(); int atomCount = 0; int bondCount = 0; while (line != null) { if (line.StartsWith("@<TRIPOS>MOLECULE")) { //logger.info("Reading molecule block"); // second line has atom/bond counts? input.ReadLine(); // disregard the name line System.String counts = input.ReadLine(); SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(counts); try { atomCount = System.Int32.Parse(tokenizer.NextToken()); } catch (System.FormatException nfExc) { System.String error = "Error while reading atom count from MOLECULE block"; //logger.error(error); //logger.debug(nfExc); throw new CDKException(error, nfExc); } if (tokenizer.HasMoreTokens()) { try { bondCount = System.Int32.Parse(tokenizer.NextToken()); } catch (System.FormatException nfExc) { System.String error = "Error while reading atom and bond counts"; //logger.error(error); //logger.debug(nfExc); throw new CDKException(error, nfExc); } } else { bondCount = 0; } //logger.info("Reading #atoms: ", atomCount); //logger.info("Reading #bonds: ", bondCount); //logger.warn("Not reading molecule qualifiers"); } else if (line.StartsWith("@<TRIPOS>ATOM")) { //logger.info("Reading atom block"); for (int i = 0; i < atomCount; i++) { line = input.ReadLine().Trim(); SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(line); tokenizer.NextToken(); // disregard the id token System.String nameStr = tokenizer.NextToken(); System.String xStr = tokenizer.NextToken(); System.String yStr = tokenizer.NextToken(); System.String zStr = tokenizer.NextToken(); System.String atomTypeStr = tokenizer.NextToken(); IAtomType atomType = atFactory.getAtomType(atomTypeStr); if (atomType == null) { atomType = atFactory.getAtomType("X"); //logger.error("Could not find specified atom type: ", atomTypeStr); } IAtom atom = molecule.Builder.newAtom("X"); atom.ID = nameStr; atom.AtomTypeName = atomTypeStr; atFactory.configure(atom); try { double x = System.Double.Parse(xStr); double y = System.Double.Parse(yStr); double z = System.Double.Parse(zStr); atom.setPoint3d(new Point3d(x, y, z)); } catch (System.FormatException nfExc) { System.String error = "Error while reading atom coordinates"; //logger.error(error); //logger.debug(nfExc); throw new CDKException(error, nfExc); } molecule.addAtom(atom); } } else if (line.StartsWith("@<TRIPOS>BOND")) { //logger.info("Reading bond block"); for (int i = 0; i < bondCount; i++) { line = input.ReadLine(); SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(line); tokenizer.NextToken(); // disregard the id token System.String atom1Str = tokenizer.NextToken(); System.String atom2Str = tokenizer.NextToken(); System.String orderStr = tokenizer.NextToken(); try { int atom1 = System.Int32.Parse(atom1Str); int atom2 = System.Int32.Parse(atom2Str); double order = 0; if ("1".Equals(orderStr)) { order = CDKConstants.BONDORDER_AROMATIC; } else if ("2".Equals(orderStr)) { order = CDKConstants.BONDORDER_DOUBLE; } else if ("3".Equals(orderStr)) { order = CDKConstants.BONDORDER_TRIPLE; } else if ("am".Equals(orderStr)) { order = CDKConstants.BONDORDER_SINGLE; } else if ("ar".Equals(orderStr)) { order = CDKConstants.BONDORDER_AROMATIC; } else if ("du".Equals(orderStr)) { order = CDKConstants.BONDORDER_SINGLE; } else if ("un".Equals(orderStr)) { order = CDKConstants.BONDORDER_SINGLE; } else if ("nc".Equals(orderStr)) { // not connected order = 0; } if (order != 0) { molecule.addBond(atom1 - 1, atom2 - 1, order); } } catch (System.FormatException nfExc) { System.String error = "Error while reading bond information"; //logger.error(error); //logger.debug(nfExc); throw new CDKException(error, nfExc); } } } line = input.ReadLine(); } } catch (System.IO.IOException exception) { System.String error = "Error while reading general structure"; //logger.error(error); //logger.debug(exception); throw new CDKException(error, exception); } return(molecule); }