public void ChooseFormatToWrite2() { StringWriter writer = new StringWriter(); SDFWriter sdfWriter = new SDFWriter(writer); sdfWriter.SetAlwaysV3000(true); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(new Atom("CH4")); sdfWriter.Write(molecule); molecule = new AtomContainer(); for (int i = 0; i < 1000; i++) { molecule.Atoms.Add(new Atom("CH4")); } sdfWriter.Write(molecule); molecule = new AtomContainer(); molecule.Atoms.Add(new Atom("CH4")); sdfWriter.Write(molecule); sdfWriter.Close(); string result = writer.ToString(); Assert.IsFalse(result.Contains("V2000")); Assert.IsTrue(result.Contains("V3000")); }
public void SetProgramName() { var sw = new StringWriter(); using (var sdfw = new SDFWriter(sw)) { try { sdfw.IOSettings[MDLV2000Writer.OptWriteDefaultProperties].Setting = "false"; sdfw.IOSettings[MDLV2000Writer.OptProgramName].Setting = "Bioclipse"; sdfw.Write(TestMoleculeFactory.Make123Triazole()); sdfw.IOSettings[SDFWriter.OptAlwaysV3000].Setting = "true"; sdfw.Write(TestMoleculeFactory.Make123Triazole()); } catch (Exception e) { Console.WriteLine(e.StackTrace); } } var sdf = sw.ToString(); foreach (var mol in sdf.Split("\\$\\$\\$\\$", 2)) { Assert.IsTrue(mol.Contains("Bioclip")); } }
public void TestIOPropPropagation() { IAtomContainer mol = TestMoleculeFactory.MakeBenzene(); foreach (var atom in mol.Atoms) { atom.IsAromatic = true; } foreach (var bond in mol.Bonds) { bond.IsAromatic = true; } StringWriter strWriter = new StringWriter(); SDFWriter writer = new SDFWriter(strWriter); var sdfWriterProps = new NameValueCollection(); sdfWriterProps["WriteAromaticBondTypes"] = "true"; writer.Listeners.Add(new PropertiesListener(sdfWriterProps)); writer.CustomizeJob(); writer.Write(mol); writer.Close(); string output = strWriter.ToString(); Assert.IsTrue(output.Contains("4 0 0 0 0")); }
public void InvalidSDfileHeaderTags() { StringWriter writer = new StringWriter(); SDFWriter sdfWriter = new SDFWriter(writer); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(new Atom("C")); molecule.SetProperty("http://not-valid.com", "URL"); sdfWriter.Write(molecule); sdfWriter.Close(); Assert.IsTrue(writer.ToString().Contains("> <http://not_valid_com>")); }
public void TestWrite_IAtomContainer_MultIAtomContainer() { StringWriter writer = new StringWriter(); SDFWriter sdfWriter = new SDFWriter(writer); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(new Atom("C")); molecule.SetProperty("foo", "bar"); sdfWriter.Write(molecule); molecule = new AtomContainer(); molecule.Atoms.Add(new Atom("C")); molecule.SetProperty("toys", "r-us"); sdfWriter.Write(molecule); sdfWriter.Close(); Assert.IsTrue(writer.ToString().IndexOf("foo") != -1); Assert.IsTrue(writer.ToString().IndexOf("bar") != -1); Assert.IsTrue(writer.ToString().IndexOf("toys") != -1); Assert.IsTrue(writer.ToString().IndexOf("r-us") != -1); Assert.IsTrue(writer.ToString().IndexOf("$$$$") != -1); }
public void TestWrite_IAtomContainerSet() { StringWriter writer = new StringWriter(); IChemObjectSet <IAtomContainer> molSet = builder.NewAtomContainerSet(); IAtomContainer molecule = builder.NewAtomContainer(); molecule.Atoms.Add(builder.NewAtom("C")); molSet.Add(molecule); SDFWriter sdfWriter = new SDFWriter(writer); sdfWriter.Write(molSet); sdfWriter.Close(); Assert.AreNotSame(0, writer.ToString().Length); }
public void TestPropertyOutput_none() { IAtomContainer adenine = TestMoleculeFactory.MakeAdenine(); StringWriter sw = new StringWriter(); SDFWriter sdf = new SDFWriter(sw, Array.Empty <string>()); adenine.SetProperty("one", "a"); adenine.SetProperty("two", "b"); sdf.Write(adenine); sdf.Close(); string output = sw.ToString(); Assert.IsFalse(output.Contains("> <two>")); Assert.IsFalse(output.Contains("> <one>")); }
public void TestWrite_IAtomContainerSet_SingleMolecule() { StringWriter writer = new StringWriter(); IChemObjectSet <IAtomContainer> molSet = new ChemObjectSet <IAtomContainer>(); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(new Atom("C")); molSet.Add(molecule); SDFWriter sdfWriter = new SDFWriter(writer); sdfWriter.Write(molSet); sdfWriter.Close(); Assert.IsTrue(writer.ToString().IndexOf("$$$$") != -1); }
public void TestWrite_IAtomContainerSet_CDKProperties() { StringWriter writer = new StringWriter(); IChemObjectSet <IAtomContainer> molSet = new ChemObjectSet <IAtomContainer>(); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(new Atom("C")); molecule.SetProperty(InvPair.CanonicalLabelPropertyKey, "bar"); molSet.Add(molecule); SDFWriter sdfWriter = new SDFWriter(writer); sdfWriter.Write(molSet); sdfWriter.Close(); Assert.IsTrue(writer.ToString().IndexOf(InvPair.CanonicalLabelPropertyKey) == -1); }
public void TestWrite_IAtomContainerSet_Properties_Off() { StringWriter writer = new StringWriter(); IChemObjectSet <IAtomContainer> molSet = new ChemObjectSet <IAtomContainer>(); var molecule = builder.NewAtomContainer(); molecule.Atoms.Add(new Atom("C")); molecule.SetProperty("foo", "bar"); molSet.Add(molecule); SDFWriter sdfWriter = new SDFWriter(writer); var sdfWriterProps = new NameValueCollection(); sdfWriterProps["writeProperties"] = "false"; sdfWriter.Listeners.Add(new PropertiesListener(sdfWriterProps)); sdfWriter.CustomizeJob(); sdfWriter.Write(molSet); sdfWriter.Close(); string result = writer.ToString(); Assert.IsFalse(result.Contains("<foo>")); }