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> /// Method which assigns van der Waals radii to the biopolymer /// default org/openscience/cdk/config/data/pdb_atomtypes.xml /// stored in the variable string vanDerWaalsFile. /// </summary> public void AssignVdWRadiiToProtein() { AtomTypeFactory atf = null; var atoms = Protein.Atoms.ToArray(); try { atf = AtomTypeFactory.GetInstance(VanDerWaalsFile); } catch (Exception ex1) { Console.Out.WriteLine($"Problem with AtomTypeFactory due to:{ex1.ToString()}"); } for (int i = 0; i < atoms.Length; i++) { try { atf.Configure(atoms[i]); } catch (Exception ex2) { Trace.TraceError($"Problem with atf.configure due to:{ex2.ToString()}"); } } }
/// <summary> /// Contructs a new PDBReader that can read Molecules from a given /// Reader. /// /// </summary> /// <param name="oIn"> The Reader to read from /// /// </param> //UPGRADE_ISSUE: Class hierarchy differences between 'java.io.Reader' and 'System.IO.StreamReader' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1186'" public PDBReader(System.IO.StreamReader oIn) { //logger = new LoggingTool(this.GetType()); //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'" _oInput = oIn; initIOSettings(); pdbFactory = null; }
private SybylAtomTypeMatcher() { var stream = ResourceLoader.GetAsStream(SYBYL_ATOM_TYPE_LIST); factory = AtomTypeFactory.GetInstance(stream, "owl"); cdkMatcher = CDK.AtomTypeMatcher; var mapStream = ResourceLoader.GetAsStream(CDK_TO_SYBYL_MAP); mapper = AtomTypeMapper.GetInstance(CDK_TO_SYBYL_MAP, mapStream); }
public void TestToString() { var factory = AtomTypeFactory.GetInstance("NCDK.Dict.Data.cdk-atom-types.owl"); var type = factory.GetAtomType("C.sp3"); Assert.IsTrue(type is ImmutableAtomType); var output = type.ToString(); Assert.IsTrue(output.Contains("ImmutableAtomType(")); Assert.IsTrue(output.Contains("MBO:")); }
public static void Script12_1() { var factory = AtomTypeFactory.GetInstance("NCDK.Dict.Data.cdk-atom-types.owl"); var atomType = factory.GetAtomType("C.sp3"); Console.WriteLine($"element: {atomType.Symbol}"); Console.WriteLine($"formal charge: {atomType.FormalCharge}"); Console.WriteLine($"hybridization: {atomType.Hybridization}"); Console.WriteLine($"neighbors: {atomType.FormalNeighbourCount}"); Console.WriteLine($"lone pairs: {atomType.GetProperty<int>(NCDK.CDKPropertyName.LonePairCount)}"); Console.WriteLine($"pi bonds: {atomType.GetProperty<int>(NCDK.CDKPropertyName.PiBondCount)}"); }
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); }
public void TestCloseEnoughToBond_IAtom_IAtom_Double() { var filename = "NCDK.Data.XYZ.viagra.xyz"; var ins = ResourceLoader.GetAsStream(filename); var reader = new XYZReader(ins); var atf = AtomTypeFactory.GetInstance("NCDK.Config.Data.jmol_atomtypes.txt"); var chemFile = reader.Read(builder.NewChemFile()); var mol = chemFile[0][0].MoleculeSet[0]; foreach (var atom in mol.Atoms) { atf.Configure(atom); } Assert.IsTrue(BondTools.CloseEnoughToBond(mol.Atoms[0], mol.Atoms[1], 1)); Assert.IsFalse(BondTools.CloseEnoughToBond(mol.Atoms[0], mol.Atoms[8], 1)); }
/// <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); }
public SmilesValencyChecker(string atomTypeList) { structgenATF = AtomTypeFactory.GetInstance(atomTypeList); Trace.TraceInformation($"Using configuration file: {atomTypeList}"); }
public SmilesValencyChecker() { structgenATF = CDK.CdkAtomTypeFactory; }