public void TestAtomValueLine() { IAtom carbon = builder.NewAtom("C"); carbon.SetProperty(CDKPropertyName.Comment, "Carbon comment"); IAtom oxygen = builder.NewAtom("O"); oxygen.SetProperty(CDKPropertyName.Comment, "Oxygen comment"); IBond bond = builder.NewBond(carbon, oxygen, BondOrder.Double); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(oxygen); molecule.Atoms.Add(carbon); molecule.Bonds.Add(bond); StringWriter writer = new StringWriter(); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.Write(molecule); mdlWriter.Close(); Assert.IsTrue(writer.ToString().IndexOf("V 1 Oxygen comment") != -1); Assert.IsTrue(writer.ToString().IndexOf("V 2 Carbon comment") != -1); }
public void TestForce2DCoordinates() { StringWriter writer = new StringWriter(); IAtomContainer molecule = builder.NewAtomContainer(); IAtom atom = builder.NewAtom("C"); atom.Point2D = new Vector2(1.0, 2.0); atom.Point3D = new Vector3(3.0, 4.0, 5.0); molecule.Atoms.Add(atom); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); var prop = new NameValueCollection { ["ForceWriteAs2DCoordinates"] = "true" }; PropertiesListener listener = new PropertiesListener(prop); mdlWriter.Listeners.Add(listener); mdlWriter.CustomizeJob(); mdlWriter.Write(molecule); mdlWriter.Close(); string output = writer.ToString(); // the current behavior is that if both 2D and 3D coordinates // are available, the 3D is outputed, and the 2D not Assert.IsTrue(output.Contains("1.0")); Assert.IsTrue(output.Contains("2.0")); }
public void TestRGPLine() { StringWriter writer = new StringWriter(); IAtomContainer molecule = builder.NewAtomContainer(); IPseudoAtom atom1 = builder.NewPseudoAtom(); atom1.Symbol = "R"; atom1.Label = "R12"; IAtom atom2 = builder.NewAtom("C"); IBond bond = builder.NewBond(atom1, atom2); IPseudoAtom atom3 = builder.NewPseudoAtom(); atom3.Symbol = "A"; atom3.Label = "A"; IBond bond2 = builder.NewBond(atom3, atom2); molecule.Atoms.Add(atom1); molecule.Atoms.Add(atom2); molecule.Atoms.Add(atom3); molecule.Bonds.Add(bond); molecule.Bonds.Add(bond2); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.Write(molecule); mdlWriter.Close(); string output = writer.ToString(); Assert.IsTrue(-1 != output.IndexOf("R#"), "Test for R#"); Assert.IsTrue(-1 != output.IndexOf("M RGP 1 1 12"), "Test for RGP line"); }
public void TestBug1649526() { //Read the original var filename = "NCDK.Data.MDL.bug-1649526.mol"; var ins = ResourceLoader.GetAsStream(filename); var reader = new MDLReader(ins); var mol = reader.Read(builder.NewAtomContainer()); reader.Close(); //Write it as cml var writer = new StringWriter(); var cmlWriter = new CMLWriter(writer); cmlWriter.Write(mol); cmlWriter.Close(); //Read this again var cmlreader = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(writer.ToString()))); var file = (IChemFile)cmlreader.Read(builder.NewChemFile()); cmlreader.Close(); //And finally write as mol var writermdl = new StringWriter(); var mdlWriter = new MDLV2000Writer(writermdl); mdlWriter.Write(file); mdlWriter.Close(); var output = writermdl.ToString().Replace("\r\n", "\n"); //if there would be 3 instances (as in the bug), the only instance wouldnt't be right at the end Assert.AreEqual(2994, output.IndexOf("M END")); //there would need some $$$$ to be in Assert.AreEqual(-1, output.IndexOf("$$$$")); //check atom/bond count Assert.AreEqual(25, output.IndexOf(" 31 33 0 0 0 0")); }
public void TestAromaticBondType4() { IAtomContainer benzene = TestMoleculeFactory.MakeBenzene(); foreach (var atom in benzene.Atoms) { atom.IsAromatic = true; } foreach (var bond in benzene.Bonds) { bond.IsAromatic = true; } StringWriter writer = new StringWriter(); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.Write(benzene); mdlWriter.Close(); Assert.IsTrue(writer.ToString().IndexOf("1 2 1 0 0 0 0") != -1); writer = new StringWriter(); mdlWriter = new MDLV2000Writer(writer); var prop = new NameValueCollection { ["WriteAromaticBondTypes"] = "true" }; PropertiesListener listener = new PropertiesListener(prop); mdlWriter.Listeners.Add(listener); mdlWriter.CustomizeJob(); mdlWriter.Write(benzene); mdlWriter.Close(); Assert.IsTrue(writer.ToString().IndexOf("1 2 4 0 0 0 0") != -1); }
/// <summary> /// Writes a MoleculeSet to an Stream for the reaction. /// </summary> /// <param name="som">The MoleculeSet that is written to an Stream</param> private void WriteAtomContainerSet(IChemObjectSet <IAtomContainer> som) { for (int i = 0; i < som.Count; i++) { IAtomContainer mol = som[i]; for (int j = 0; j < som.GetMultiplier(i); j++) { StringWriter sw = new StringWriter(); writer.Write("$MOL"); writer.Write('\n'); MDLV2000Writer mdlwriter = null; try { mdlwriter = new MDLV2000Writer(sw); } catch (Exception ex) { Trace.TraceError(ex.Message); Debug.WriteLine(ex); throw new CDKException("Exception while creating MDLWriter: " + ex.Message, ex); } mdlwriter.Write(mol); mdlwriter.Close(); writer.Write(sw.ToString()); } } }
public void TestUnsupportedBondOrder() { var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms.Add(builder.NewAtom("C")); molecule.Bonds.Add(builder.NewBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Quadruple)); MDLV2000Writer mdlWriter = new MDLV2000Writer(new StringWriter()); mdlWriter.Write(molecule); mdlWriter.Close(); }
/// <summary> /// Convert mol to V2000 Molfile /// </summary> /// <param name="mol"></param> /// <returns></returns> public static string AtomContainerToMolfile(IAtomContainer mol) { StringWriter sw = new StringWriter(); MDLV2000Writer writer = new MDLV2000Writer(sw); writer.Write(mol); writer.Close(); sw.Close(); string molFile = sw.ToString(); return(molFile); }
public void TestBug890456() { StringWriter writer = new StringWriter(); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewPseudoAtom("*")); molecule.Atoms.Add(builder.NewAtom("C")); molecule.Atoms.Add(builder.NewAtom("C")); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.Write(molecule); mdlWriter.Close(); Assert.IsTrue(writer.ToString().IndexOf("M END") != -1); }
public void TestWriteStringAtomAtomMapping() { StringWriter writer = new StringWriter(); IAtomContainer molecule = TestMoleculeFactory.MakeAlphaPinene(); molecule.Atoms[0].SetProperty(CDKPropertyName.AtomAtomMapping, "1"); molecule.Atoms[1].SetProperty(CDKPropertyName.AtomAtomMapping, "15"); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.Write(molecule); mdlWriter.Close(); string output = writer.ToString(); Assert.IsTrue(output.Contains("0 0 0 0 0 0 0 0 0 1 0 0")); Assert.IsTrue(output.Contains("0 0 0 0 0 0 0 0 0 15 0 0")); }
public void TestUndefinedStereo() { IAtomContainer mol = TestMoleculeFactory.MakeAlphaPinene(); mol.Bonds[0].Stereo = BondStereo.UpOrDown; mol.Bonds[1].Stereo = BondStereo.EOrZ; StringWriter writer = new StringWriter(); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.Write(mol); mdlWriter.Close(); string output = writer.ToString(); Assert.IsTrue(output.IndexOf("1 2 2 4 0 0 0") > -1); Assert.IsTrue(output.IndexOf("2 3 1 3 0 0 0") > -1); }
public void TestBug1212219() { StringWriter writer = new StringWriter(); var molecule = builder.NewAtomContainer(); var atom = builder.NewAtom("C"); atom.MassNumber = 14; molecule.Atoms.Add(atom); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.Write(molecule); mdlWriter.Close(); string output = writer.ToString(); //Debug.WriteLine($"MDL output for testBug1212219: {output}"); Assert.IsTrue(output.IndexOf("M ISO 1 1 14") != -1); }
public void TestAtomParity() { var ins = ResourceLoader.GetAsStream("NCDK.Data.MDL.mol_testAtomParity.mol"); var reader = new MDLV2000Reader(ins); IAtomContainer molecule = builder.NewAtomContainer(); molecule = reader.Read(molecule); reader.Close(); StringWriter sw = new StringWriter(); MDLV2000Writer writer = new MDLV2000Writer(sw); writer.Write(molecule); writer.Close(); Assert.IsTrue(sw.ToString().Contains( " -1.1749 0.1436 0.0000 C 0 0 1 0 0 0 0 0 0 0 0 0")); }
public void TestWriteInvalidAtomAtomMapping() { StringWriter writer = new StringWriter(); IAtomContainer molecule = TestMoleculeFactory.MakeAlphaPinene(); molecule.Atoms[0].SetProperty(CDKPropertyName.AtomAtomMapping, "1a"); molecule.Atoms[1].SetProperty(CDKPropertyName.AtomAtomMapping, "15"); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.Write(molecule); mdlWriter.Close(); string output = writer.ToString(); Regex p = new Regex(".*V2000.* 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 " + "0 0.* 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 15 0 0.*", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); var m = p.Match(output); Assert.IsTrue(m.Success); }
public void TestSingleTripletRadical() { var ins = ResourceLoader.GetAsStream("NCDK.Data.MDL.singleTripletRadical.mol"); var reader = new MDLV2000Reader(ins); IAtomContainer molecule = builder.NewAtomContainer(); molecule = reader.Read(molecule); reader.Close(); StringWriter sw = new StringWriter(); MDLV2000Writer writer = new MDLV2000Writer(sw); writer.Write(molecule); writer.Close(); string[] lines = SplitLines(sw.ToString()); Assert.AreEqual(9, lines.Length, "incorrect file length"); Assert.AreEqual("M RAD 1 2 1", lines[7], "incorrect radical output"); }
public void TestAlias_TruncatedLabel() { IAtomContainer container = builder.NewAtomContainer(); string label = "This is a very long label - almost too long. it should be cut here -> and the rest is truncated"; container.Atoms.Add(builder.NewPseudoAtom(label)); StringWriter sw = new StringWriter(); MDLV2000Writer writer = new MDLV2000Writer(sw); writer.Write(container); writer.Close(); string output = sw.ToString(); Assert.IsTrue(output.Contains("This is a very long label - almost too long. it should be cut here ->")); // make sure the full label wasn't output Assert.IsFalse(output.Contains(label)); }
public void TestWritePseudoAtoms() { var ins = ResourceLoader.GetAsStream("NCDK.Data.MDL.pseudoatoms.sdf"); var reader = new MDLV2000Reader(ins); IAtomContainer molecule = builder.NewAtomContainer(); molecule = reader.Read(molecule); reader.Close(); StringWriter writer = new StringWriter(); MDLV2000Writer mwriter = new MDLV2000Writer(writer); mwriter.Write(molecule); mwriter.Close(); string output = writer.ToString(); Assert.IsTrue(output.IndexOf("Gln") != -1); Assert.IsTrue(output.IndexOf("Leu") != -1); }
public void TestWriteValence() { StringWriter writer = new StringWriter(); IAtomContainer molecule = TestMoleculeFactory.MakeAlphaPinene(); molecule.Atoms[0].Valency = 1; molecule.Atoms[1].Valency = 0; MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); var customSettings = new NameValueCollection { ["WriteQueryFormatValencies"] = "true" }; mdlWriter.Listeners.Add(new PropertiesListener(customSettings)); mdlWriter.Write(molecule); mdlWriter.Close(); string output = writer.ToString(); Assert.IsTrue(output.IndexOf("0 0 0 0 0 1 0 0 0 0 0 0") != -1); Assert.IsTrue(output.IndexOf("0 0 0 0 0 15 0 0 0 0 0 0") != -1); }
public void TestRGPLine_Multiline() { IAtomContainer container = builder.NewAtomContainer(); for (int i = 1; i < 20; i++) { container.Atoms.Add(builder.NewPseudoAtom("R" + i)); } StringWriter sw = new StringWriter(); MDLV2000Writer writer = new MDLV2000Writer(sw); writer.Write(container); writer.Close(); string output = sw.ToString(); Assert.IsTrue(output.Contains("M RGP 8 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8")); Assert.IsTrue(output.Contains("M RGP 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16")); Assert.IsTrue(output.Contains("M RGP 3 17 17 18 18 19 19")); }
public void TestWritePseudoAtoms_LongLabel() { IAtomContainer container = builder.NewAtomContainer(); IAtom c1 = builder.NewAtom("C"); IAtom tRNA = builder.NewPseudoAtom("tRNA"); container.Atoms.Add(c1); container.Atoms.Add(tRNA); StringWriter sw = new StringWriter(); MDLV2000Writer writer = new MDLV2000Writer(sw); writer.Write(container); writer.Close(); string output = sw.ToString(); Assert.IsTrue(output.Contains("A 2")); Assert.IsTrue(output.Contains("tRNA")); }
public void TestNullFormalCharge() { StringWriter writer = new StringWriter(); IAtomContainer molecule = builder.NewAtomContainer(); IAtom atom = builder.NewAtom("C"); atom.FormalCharge = null; molecule.Atoms.Add(atom); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.Write(molecule); mdlWriter.Close(); string output = writer.ToString(); // test ensures that the writer does not throw an exception on // null formal charges, so a mere assert on output being non-zero // length is enough Assert.IsNotNull(output); Assert.AreNotSame(0, output.Length); }
public void TestTwoFragmentsWithTitle() { IAtomContainer mol1 = TestMoleculeFactory.MakeAlphaPinene(); mol1.Title = "title1"; IAtomContainer mol2 = TestMoleculeFactory.MakeAlphaPinene(); mol2.Title = "title2"; var model = mol1.Builder.NewChemModel(); model.MoleculeSet = mol1.Builder.NewAtomContainerSet(); model.MoleculeSet.Add(mol1); model.MoleculeSet.Add(mol2); StringWriter writer = new StringWriter(); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.Write(model); mdlWriter.Close(); string output = writer.ToString(); Assert.IsTrue(output.Contains("title1; title2")); }
public void TestMultipleRadicals() { var ins = ResourceLoader.GetAsStream("NCDK.Data.MDL.multipleRadicals.mol"); var reader = new MDLV2000Reader(ins); IAtomContainer molecule = builder.NewAtomContainer(); molecule = reader.Read(molecule); reader.Close(); StringWriter sw = new StringWriter(); MDLV2000Writer writer = new MDLV2000Writer(sw); writer.Write(molecule); writer.Close(); string[] lines = SplitLines(sw.ToString()); Assert.AreEqual(24, lines.Length, "incorrect file length"); Assert.AreEqual("M RAD 8 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2", lines[21], "incorrect radical output on line 22"); Assert.AreEqual("M RAD 1 9 2", lines[22], "incorrect radical output on line 23"); }
public void TestWritePseudoAtoms_nullLabel() { IAtomContainer container = builder.NewAtomContainer(); IAtom c1 = builder.NewAtom("C"); IPseudoAtom nullAtom = builder.NewPseudoAtom(""); nullAtom.Label = null; container.Atoms.Add(c1); container.Atoms.Add(nullAtom); StringWriter sw = new StringWriter(); MDLV2000Writer writer = new MDLV2000Writer(sw); writer.Write(container); writer.Close(); string output = sw.ToString(); Assert.IsTrue(output.Contains("R")); }
public void TestBug1778479() { StringWriter writer = new StringWriter(); IAtomContainer molecule = builder.NewAtomContainer(); IAtom atom1 = builder.NewPseudoAtom(); IAtom atom2 = builder.NewAtom("C"); IBond bond = builder.NewBond(atom1, atom2); molecule.Atoms.Add(atom1); molecule.Atoms.Add(atom2); molecule.Bonds.Add(bond); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.Write(molecule); mdlWriter.Close(); string output = writer.ToString(); Assert.AreEqual(-1, output.IndexOf("0.0000 0.0000 0.0000 0 0 0 0 0 0 0 0 0 0 0 0"), "Test for zero length pseudo atom label in MDL file"); }
public void TestPrefer3DCoordinateOutput() { StringWriter writer = new StringWriter(); IAtomContainer molecule = builder.NewAtomContainer(); IAtom atom = builder.NewAtom("C"); atom.Point2D = new Vector2(1.0, 2.0); atom.Point3D = new Vector3(3.0, 4.0, 5.0); molecule.Atoms.Add(atom); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.Write(molecule); mdlWriter.Close(); string output = writer.ToString(); // the current behavior is that if both 2D and 3D coordinates // are available, the 3D is outputed, and the 2D not Assert.IsTrue(output.Contains("3.0")); Assert.IsTrue(output.Contains("4.0")); Assert.IsTrue(output.Contains("5.0")); }
/// <summary> /// Produces a CTAB block for an atomContainer, without the header lines. /// </summary> /// <param name="atomContainer"></param> /// <returns>CTAB block</returns> private static string GetCTAB(IAtomContainer atomContainer) { StringWriter strWriter = new StringWriter(); MDLV2000Writer mdlWriter = new MDLV2000Writer(strWriter); mdlWriter.Write(atomContainer); try { mdlWriter.Close(); } catch (IOException) { // FIXME } string ctab = strWriter.ToString(); //strip of the individual header, as we have one super header instead. for (int line = 1; line <= 3; line++) { ctab = ctab.Substring(ctab.IndexOf(LSEP, StringComparison.Ordinal) + (LSEP.Length)); } return(ctab); }