public void RadicalCanon() { var builder = CDK.Builder; IAtomContainer mola = builder.NewAtomContainer(); mola.Atoms.Add(builder.NewAtom("CH3")); mola.Atoms.Add(builder.NewAtom("CH2")); mola.Atoms.Add(builder.NewAtom("CH2")); mola.Atoms.Add(builder.NewAtom("CH2")); mola.Atoms.Add(builder.NewAtom("CH2")); mola.Atoms.Add(builder.NewAtom("CH1")); mola.Atoms.Add(builder.NewAtom("CH3")); mola.AddBond(mola.Atoms[1], mola.Atoms[2], BondOrder.Single); mola.AddBond(mola.Atoms[2], mola.Atoms[3], BondOrder.Single); mola.AddBond(mola.Atoms[3], mola.Atoms[4], BondOrder.Single); mola.AddBond(mola.Atoms[4], mola.Atoms[5], BondOrder.Single); mola.AddBond(mola.Atoms[5], mola.Atoms[6], BondOrder.Single); mola.AddBond(mola.Atoms[0], mola.Atoms[5], BondOrder.Single); mola.AddSingleElectronTo(mola.Atoms[1]); SmilesParser smipar = new SmilesParser(builder); var molb = smipar.ParseSmiles("CC(CCC[CH2])C |^1:5|"); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.Canonical | SmiFlavors.CxRadical); Assert.AreEqual(smigen.Create(molb), smigen.Create(mola)); }
public void CanonAtomLabels() { var mol = smipar.ParseSmiles("c1ccccc1O |$_AV:0;1;2;3;4;5;6$|"); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.Canonical | SmiFlavors.CxAtomValue); Assert.AreEqual("OC=1C=CC=CC1 |$_AV:6;5;0;1;2;3;4$|", smigen.Create(mol)); }
public void RoundTripReactionAtomLabelsAndFragmentGroups() { IReaction rxn = smipar.ParseReactionSmiles("CC(C)c1ccccc1.ClC([*])=O>ClCCl.[Al+3].[Cl-].[Cl-].[Cl-]>CC(C)c1ccc(cc1)C([*])=O |$;;;;;;;;;;;R1;;;;;;;;;;;;;;;;;;;R1;$,f:3.4.5.6|"); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.CxAtomLabel | SmiFlavors.CxFragmentGroup); Assert.AreEqual("CC(C)C1=CC=CC=C1.ClC(*)=O>ClCCl.[Al+3].[Cl-].[Cl-].[Cl-]>CC(C)C1=CC=C(C=C1)C(*)=O |f:3.4.5.6,$;;;;;;;;;;;R1;;;;;;;;;;;;;;;;;;;R1$|", smigen.Create(rxn)); }
public void RoundTripRadicals() { var mol = smipar.ParseSmiles("[C]1C[CH][CH]OC1 |^1:2,3,^2:0|"); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.CxRadical); string smi = smigen.Create(mol); Assert.AreEqual("[C]1C[CH][CH]OC1 |^1:2,3,^2:0|", smi); }
public void NoCoordsInEtOH() { var mol = smipar.ParseSmiles("CCO"); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.CxCoordinates); string smi = smigen.Create(mol); Assert.AreEqual("CCO", smi); }
public void NoCoordsOptEtOH() { var mol = smipar.ParseSmiles("CCO |(,,;1,1,;2,2,)|"); SmilesGenerator smigen = new SmilesGenerator(0); string smi = smigen.Create(mol); Assert.AreEqual("CCO", smi); }
public void CoordsEtOH() { var mol = smipar.ParseSmiles("CCO |(,,;1,1,;2,2,)|"); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.CxCoordinates); string smi = smigen.Create(mol); Assert.AreEqual("CCO |(,,;1,1,;2,2,)|", smi); }
public void RoundTripPEGn() { var mol = smipar.ParseSmiles("CCCOCCO |Sg:n:1,2,3::ht|"); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.CxPolymer); string smi = smigen.Create(mol); Assert.AreEqual("CCCOCCO |Sg:n:1,2,3:n:ht|", smi); }
public void RoundTripMulticenter() { var mol = smipar.ParseSmiles("c1ccccc1.*Cl |m:6:0.1.2.3.4.5|"); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.UseAromaticSymbols | SmiFlavors.CxMulticenter); string smi = smigen.Create(mol); Assert.AreEqual("c1ccccc1.*Cl |m:6:0.1.2.3.4.5|", smi); }
public void Chembl367774() { using (MDLV2000Reader mdlr = new MDLV2000Reader(GetType().Assembly.GetManifestResourceStream(GetType(), "CHEMBL367774.mol"))) { IAtomContainer container = mdlr.Read(builder.NewAtomContainer()); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.CxSmiles); Assert.AreEqual("OC(=O)C1=CC(F)=CC=2NC(=NC12)C3=CC=C(C=C3F)C4=CC=CC=C4", smigen.Create(container)); } }
public void CanonicalReactionAtomLabelsAndFragmentGroups() { IReaction rxn1 = smipar.ParseReactionSmiles("CC(C)c1ccccc1.ClC([*])=O>[Al+3].[Cl-].[Cl-].[Cl-].ClCCl>CC(C)c1ccc(cc1)C([*])=O |$;;;;;;;;;;;R1;;;;;;;;;;;;;;;;;;;R1;$,f:2.3.4.5|"); IReaction rxn2 = smipar.ParseReactionSmiles("ClC([*])=O.CC(C)c1ccccc1>[Al+3].[Cl-].[Cl-].[Cl-].ClCCl>CC(C)c1ccc(cc1)C([*])=O |$;;R1;;;;;;;;;;;;;;;;;;;;;;;;;;;;R1;$,f:2.3.5.4|"); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.CxAtomLabel | SmiFlavors.CxFragmentGroup | SmiFlavors.Canonical); Assert.AreEqual(smigen.Create(rxn2), smigen.Create(rxn1)); }
public void CanonMulticenter() { var mol = smipar.ParseSmiles("c1ccccc1.*Cl |m:6:0.1.2.3.4.5|"); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.UseAromaticSymbols | SmiFlavors.CxMulticenter | SmiFlavors.Canonical); string smi = smigen.Create(mol); Assert.AreEqual("*Cl.c1ccccc1 |m:0:2.3.4.5.6.7|", smi); }
public void Chebi53695() { using (var ins = GetType().Assembly.GetManifestResourceStream(GetType(), "CHEBI_53695.mol")) using (var mdlr = new MDLV2000Reader(ins)) { IAtomContainer mol = mdlr.Read(CDK.Builder.NewAtomContainer()); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.CxSmiles | SmiFlavors.AtomicMassStrict); Assert.AreEqual("C(C(=O)OC)(C*)*C(C(C1=C(C(=C(C(=C1[2H])[2H])[2H])[2H])[2H])(*)[2H])([2H])[2H] |Sg:n:0,1,2,3,4,5:n:ht,Sg:n:8,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24:m:ht|", smigen.Create(mol)); } }
public void GenerateLabelledSmiles() { var mol = new AtomContainer(); mol.Atoms.Add(new Atom("C")); mol.Atoms[0].ImplicitHydrogenCount = 3; mol.Atoms.Add(new Atom("C")); mol.Atoms[1].ImplicitHydrogenCount = 2; mol.Atoms.Add(new PseudoAtom("R1")); mol.Atoms[2].ImplicitHydrogenCount = 0; mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Single); mol.AddBond(mol.Atoms[1], mol.Atoms[2], BondOrder.Single); SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.CxAtomLabel); string smi = smigen.Create(mol); Assert.AreEqual("CC* |$;;R1$|", smi); }
static void Main() { { #region SmiFlavors SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.Isomeric); #endregion } { #region SmiFlavor_Isomeric SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.Stereo | SmiFlavors.AtomicMass); #endregion } { string smi = null; SmilesGenerator sg = null; { #region 1 IAtomContainer ethanol = TestMoleculeFactory.MakeEthanol(); sg = new SmilesGenerator(SmiFlavors.Generic); smi = sg.Create(ethanol); // CCO, C(C)O, C(O)C, or OCC sg = SmilesGenerator.Unique; smi = sg.Create(ethanol); // only CCO #endregion #region 2 IAtomContainer benzene = TestMoleculeFactory.MakeBenzene(); // 'benzene' molecule has no arom flags, we always get Kekulé output sg = new SmilesGenerator(SmiFlavors.Generic); smi = sg.Create(benzene); // C1=CC=CC=C1 sg = new SmilesGenerator(SmiFlavors.Generic | SmiFlavors.UseAromaticSymbols); smi = sg.Create(benzene); // C1=CC=CC=C1 flags not set! // Note, in practice we'd use an aromaticity algorithm foreach (IAtom a in benzene.Atoms) { a.IsAromatic = true; } foreach (IBond b in benzene.Bonds) { b.IsAromatic = true; } // 'benzene' molecule now has arom flags, we always get aromatic SMILES if we request it sg = new SmilesGenerator(SmiFlavors.Generic); smi = sg.Create(benzene); // C1=CC=CC=C1 sg = new SmilesGenerator(SmiFlavors.Generic | SmiFlavors.UseAromaticSymbols); smi = sg.Create(benzene); // c1ccccc1 #endregion } } { #region 4 IAtomContainer mol = TestMoleculeFactory.MakeAlphaPinene(); SmilesGenerator sg = new SmilesGenerator(SmiFlavors.Generic); int n = mol.Atoms.Count; int[] order = new int[n]; // the order array is filled up as the SMILES is generated string smi = sg.Create(mol, order); // load the coordinates array such that they are in the order the atoms // are read when parsing the SMILES Vector2[] coords = new Vector2[mol.Atoms.Count]; for (int i = 0; i < coords.Length; i++) { coords[order[i]] = mol.Atoms[i].Point2D.Value; } // SMILES string suffixed by the coordinates string smi2d = smi + " " + Arrays.ToJavaString(coords); #endregion } { #region 5 ctor_SmiFlavor SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.Stereo | SmiFlavors.Canonical); #endregion } { #region Aromatic SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.UseAromaticSymbols); #endregion } { IAtomContainer container = null; #region WithAtomClasses SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.AtomAtomMap); smigen.CreateSMILES(container); // C[CH2:4]O second atom has class = 4 #endregion } { #region WithAtomClasses IAtomContainer container = TestMoleculeFactory.MakeAlphaPinene(); SmilesGenerator smilesGen = SmilesGenerator.Unique.WithAtomClasses(); smilesGen.CreateSMILES(container); // C[CH2:4]O second atom has class = 4 #endregion } { #region Create_IAtomContainer_int IAtomContainer mol = TestMoleculeFactory.MakeAlphaPinene(); SmilesGenerator sg = new SmilesGenerator(); int n = mol.Atoms.Count; int[] order = new int[n]; // the order array is filled up as the SMILES is generated string smi = sg.Create(mol, order); // load the coordinates array such that they are in the order the atoms // are read when parsing the SMILES Vector2[] coords = new Vector2[mol.Atoms.Count]; for (int i = 0; i < coords.Length; i++) { coords[order[i]] = mol.Atoms[i].Point2D.Value; } // SMILES string suffixed by the coordinates string smi2d = smi + " " + Arrays.ToJavaString(coords); #endregion } { IAtomContainer container = null; #region Create_IAtomContainer_int_int IAtomContainer mol = TestMoleculeFactory.MakeAlphaPinene(); SmilesGenerator sg = new SmilesGenerator(); int n = mol.Atoms.Count; int[] order = new int[n]; // the order array is filled up as the SMILES is generated string smi = sg.Create(mol, order); // load the coordinates array such that they are in the order the atoms // are read when parsing the SMILES Vector2[] coords = new Vector2[mol.Atoms.Count]; for (int i = 0; i < coords.Length; i++) { coords[order[i]] = container.Atoms[i].Point2D.Value; } // SMILES string suffixed by the coordinates string smi2d = smi + " " + Arrays.ToJavaString(coords); #endregion } }