Re: [Rdkit-discuss] Draw.MolToImage upside down
Thanks Rocco! I just used AllChem.GenerateDepictionMatching2DStructure() with a custom SMILES string as the template depiction for each resonance structure. Due to the alternating double bonds switching places between the two resonance structures, FindMCS did not seem to provide a SMARTS string as a template depiction that worked for both resonance structures, so I wrote SMILES strings as template depictions for each resonance structure and confirmed that each substructure template has the same orientation. Here is the working script: from rdkit import Chem from rdkit.Chem import Draw, AllChem import matplotlib.pyplot as plt def draw_structure(mol_smiles_string, template_smiles_string, ax=None): if not ax: f, ax = plt.subplots() m = Chem.MolFromSmiles(mol_smiles_string, sanitize=False) m.UpdatePropertyCache() Chem.SetHybridization(m) t = Chem.MolFromSmiles(template_smiles_string, sanitize=False) t.UpdatePropertyCache() Chem.SetHybridization(t) AllChem.Compute2DCoords(t) AllChem.GenerateDepictionMatching2DStructure(m, t) img = Draw.MolToImage(m) return ax.imshow(img, interpolation='bessel') fig = plt.figure(figsize=(10,5)) ax1 = plt.subplot2grid((1, 2), (0, 0)) ax2 = plt.subplot2grid((1, 2), (0, 1)) draw_structure(mol_smiles_string="CN(C2=O)C(C)=N\C2=C/C1=CC(F)=C([o-])C(F)=C1", template_smiles_string="C=C/C1=CC(F)=C([o-])C(F)=C1", ax=ax1) draw_structure(mol_smiles_string="CN(C=2[o-])C(C)=N\C2C=C1/C=C(F)C(=O)C(F)=C1", template_smiles_string="CC=C1/C=C(F)C(=O)C(F)=C1", ax=ax2) plt.tight_layout() plt.show() Output: [image: image.png] Best, Jason On Thu, Sep 20, 2018 at 3:09 PM Rocco Moretti wrote: > Instead of arbitrarily generating 2D coordinates (which can have any > orientation), you probably want to use > GenerateDepictionMatching2DStructure() to generate coordinates which match > a common orientation for a substructure. > > See > http://www.rdkit.org/docs/GettingStartedInPython.html#drawing-molecules > for an example of how to use it. > > Note that this does require you to have a common core with which to align > the depictions, but some of that can be automated with FindMCS (see > http://www.rdkit.org/docs/GettingStartedInPython.html#maximum-common-substructure > ). > > On Thu, Sep 20, 2018 at 4:54 PM, Jason Klima > wrote: > >> Hi, >> I would like to visualize the following resonance structures in the same >> orientation (i.e. the same atomic coordinates), however, the image on the >> right appears to be drawn upside down compared to the image on the left, >> while the element names (e.g. N, O, and F) in both images are right side >> up. Mirroring the image on the right about a horizontal axis can be >> accomplished with ax.set_ylim([0,300]) however the element names are >> then upside down. How can I mirror the drawing on the right about a >> horizontal axis without mirroring element names? >> >> from rdkit import Chem >> from rdkit.Chem import Draw >> import matplotlib.pyplot as plt >> def draw_structure(smiles_string, ax=None): >> m = Chem.MolFromSmiles(smiles_string, sanitize=False) >> m.UpdatePropertyCache() >> Chem.SetHybridization(m) >> # ax.set_ylim([0,300]) # Flips image but element names also flip >> return ax.imshow(Draw.MolToImage(m), interpolation='bessel') >> fig = plt.figure(figsize=(10,5)) >> ax1 = plt.subplot2grid((1, 2), (0, 0)) >> ax2 = plt.subplot2grid((1, 2), (0, 1)) >> draw_structure('CN(C2=O)C(C)=N\C2=C/C1=CC(F)=C([o-])C(F)=C1', ax=ax1) >> draw_structure('CN(C=2[o-])C(C)=N\C2C=C1/C=C(F)C(=O)C(F)=C1', ax=ax2) >> plt.tight_layout() >> plt.show() >> >> Output: >> [image: image.png] >> >> Thanks, >> Jason >> >> >> ___ >> Rdkit-discuss mailing list >> Rdkit-discuss@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss >> >> > -- Jason Klima Graduate Research Assistant Department of Biochemistry University of Washington, Seattle ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
Re: [Rdkit-discuss] Draw.MolToImage upside down
Instead of arbitrarily generating 2D coordinates (which can have any orientation), you probably want to use GenerateDepictionMatching2DStructure() to generate coordinates which match a common orientation for a substructure. See http://www.rdkit.org/docs/GettingStartedInPython.html#drawing-molecules for an example of how to use it. Note that this does require you to have a common core with which to align the depictions, but some of that can be automated with FindMCS (see http://www.rdkit.org/docs/GettingStartedInPython.html#maximum-common-substructure ). On Thu, Sep 20, 2018 at 4:54 PM, Jason Klima wrote: > Hi, > I would like to visualize the following resonance structures in the same > orientation (i.e. the same atomic coordinates), however, the image on the > right appears to be drawn upside down compared to the image on the left, > while the element names (e.g. N, O, and F) in both images are right side > up. Mirroring the image on the right about a horizontal axis can be > accomplished with ax.set_ylim([0,300]) however the element names are then > upside down. How can I mirror the drawing on the right about a horizontal > axis without mirroring element names? > > from rdkit import Chem > from rdkit.Chem import Draw > import matplotlib.pyplot as plt > def draw_structure(smiles_string, ax=None): > m = Chem.MolFromSmiles(smiles_string, sanitize=False) > m.UpdatePropertyCache() > Chem.SetHybridization(m) > # ax.set_ylim([0,300]) # Flips image but element names also flip > return ax.imshow(Draw.MolToImage(m), interpolation='bessel') > fig = plt.figure(figsize=(10,5)) > ax1 = plt.subplot2grid((1, 2), (0, 0)) > ax2 = plt.subplot2grid((1, 2), (0, 1)) > draw_structure('CN(C2=O)C(C)=N\C2=C/C1=CC(F)=C([o-])C(F)=C1', ax=ax1) > draw_structure('CN(C=2[o-])C(C)=N\C2C=C1/C=C(F)C(=O)C(F)=C1', ax=ax2) > plt.tight_layout() > plt.show() > > Output: > [image: image.png] > > Thanks, > Jason > > > ___ > Rdkit-discuss mailing list > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss > > ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
[Rdkit-discuss] Draw.MolToImage upside down
Hi, I would like to visualize the following resonance structures in the same orientation (i.e. the same atomic coordinates), however, the image on the right appears to be drawn upside down compared to the image on the left, while the element names (e.g. N, O, and F) in both images are right side up. Mirroring the image on the right about a horizontal axis can be accomplished with ax.set_ylim([0,300]) however the element names are then upside down. How can I mirror the drawing on the right about a horizontal axis without mirroring element names? from rdkit import Chem from rdkit.Chem import Draw import matplotlib.pyplot as plt def draw_structure(smiles_string, ax=None): m = Chem.MolFromSmiles(smiles_string, sanitize=False) m.UpdatePropertyCache() Chem.SetHybridization(m) # ax.set_ylim([0,300]) # Flips image but element names also flip return ax.imshow(Draw.MolToImage(m), interpolation='bessel') fig = plt.figure(figsize=(10,5)) ax1 = plt.subplot2grid((1, 2), (0, 0)) ax2 = plt.subplot2grid((1, 2), (0, 1)) draw_structure('CN(C2=O)C(C)=N\C2=C/C1=CC(F)=C([o-])C(F)=C1', ax=ax1) draw_structure('CN(C=2[o-])C(C)=N\C2C=C1/C=C(F)C(=O)C(F)=C1', ax=ax2) plt.tight_layout() plt.show() Output: [image: image.png] Thanks, Jason ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
[Rdkit-discuss] Butina clustering with additional output
RDkit Discussion Group, I note that RDkit can perform Butina clustering. Given an SDF ofsmall molecules I would like to cluster the ligands, but obtain additionalinformation from the clustering algorithm. In particular, I would like to obtainthe cluster number and Tanimoto distance from the centroid for every ligandin the SDF. The centroid would obviously have a distance of 0.00. Has anyone written additional RDkit code to extract this additional information? Thank you. Regards, Jim Metz ___ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss