public void TestPseudoAtomLabels() { using (var ins = ResourceLoader.GetAsStream("NCDK.Data.MDL.pseudoatomsv3000.mol")) using (MDLV3000Reader reader = new MDLV3000Reader(ins)) { IAtomContainer molecule = builder.NewAtomContainer(); molecule = reader.Read(molecule); reader.Close(); Assert.IsTrue(molecule.Atoms[9] is IPseudoAtom); Assert.AreEqual("R", molecule.Atoms[9].Symbol); IPseudoAtom pa = (IPseudoAtom)molecule.Atoms[9]; Assert.AreEqual("Leu", pa.Label); } }
public void TestEmptyString() { string emptyString = ""; try { using (MDLV3000Reader reader = new MDLV3000Reader(new StringReader(emptyString))) { reader.Read(builder.NewAtomContainer()); reader.Close(); Assert.Fail("Should have received a CDK Exception"); } } catch (CDKException cdkEx) { Assert.AreEqual("Expected a header line, but found nothing.", cdkEx.Message); } }
public void TestBug1571207() { var filename = "NCDK.Data.MDL.molV3000.mol"; Trace.TraceInformation("Testing: " + filename); using (var ins = ResourceLoader.GetAsStream(filename)) { MDLV3000Reader reader = new MDLV3000Reader(ins); IAtomContainer m = reader.Read(builder.NewAtomContainer()); reader.Close(); Assert.IsNotNull(m); Assert.AreEqual(31, m.Atoms.Count); Assert.AreEqual(34, m.Bonds.Count); IAtom atom = m.Atoms[0]; Assert.IsNotNull(atom); Assert.IsNotNull(atom.Point2D); Assert.AreEqual(10.4341, atom.Point2D.Value.X, 0.0001); Assert.AreEqual(5.1053, atom.Point2D.Value.Y, 0.0001); } }
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); }