コード例 #1
0
def show_docked(df):
    oechem = import_("openeye.oechem")
    if not oechem.OEChemIsLicensed(): raise(ImportError("Need License for OEChem!"))
    # def show_docked(df):

    mol2_blocks_docked = list(df['mol2_blocks_docked'])
    smiles_template = list(df['smiles'])
    names = list(df['names'])
    v = PyMol.MolViewer()
    v.DeleteAll()
    for count,molblock in enumerate(mol2_blocks_docked):

        molout = mol2_string_IO_san(molblock)
        mol = Chem.MolFromPDBBlock(molout)
        template = Chem.MolFromSmiles(smiles_template[count])
        new_mol = AllChem.AssignBondOrdersFromTemplate(template, mol)
    #     mol2_blocks_template = Chem.MolFromMol2Block(molblock)
        print(type(new_mol))

        molid = names[count]
        print(molid)
        mol.SetProp('_Name', molid)

        probe = Chem.Mol(new_mol.ToBinary())
        v.ShowMol(probe, name=molid, showOnly=False)
コード例 #2
0
def mols_to_pymol(df):
    v = PyMol.MolViewer()
    v.DeleteAll()
    mols = [Chem.MolFromMol2Block(m, removeHs=False) for m in df['mol_block_am1bcc']]
    names = list(df['names'])
    for count,m in enumerate(mols):
        molid = names[count]
        m.SetProp('_Name', molid)
        probe = Chem.Mol(m.ToBinary())
        v.ShowMol(probe, name=molid, showOnly=False)
コード例 #3
0
def mols_to_pymol(mols, names):
    v = PyMol.MolViewer()
    v.DeleteAll()
    mols_3d = [dm.conformers.generate(m, n_confs=1) for m in mols]
#     names = list(df['names'])
    for count,m in enumerate(mols_3d):
        molid = names[count]
        m.SetProp('_Name', molid)
        
        probe = Chem.Mol(m.ToBinary())
        v.ShowMol(probe, name=molid, showOnly=False)
コード例 #4
0
ファイル: lab.py プロジェクト: avbelyaev/BMSTU
def main():
    smiles = [EPINEPHRINE, CLONIPIDINE]

    mols = [Chem.MolFromSmiles(m) for m in smiles]
    mols = [Chem.AddHs(m) for m in mols]

    i = 0
    for m in mols:
        print(m)
        AllChem.EmbedMolecule(m)
        AllChem.MMFFOptimizeMolecule(m, maxIters=200)
        Chem.MolToMolFile(m, '{0}.mol'.format(i))

        Draw.MolToFile(m, 'm{0}.png'.format(i))
        i += 1

    refMol1 = AllChem.MMFFGetMoleculeProperties(mols[0])
    refMol2 = AllChem.MMFFGetMoleculeProperties(mols[1])

    # somehow this shit is the key
    pyO3A = AllChem.GetO3A(mols[0], mols[1], refMol1, refMol2)
    print('align')
    print(pyO3A.Align())
    print(pyO3A.Matches())

    Chem.MolToMolFile(mols[0], '0_.mol')
    Chem.MolToMolFile(mols[1], '1_.mol')

    ff = AllChem.UFFGetMoleculeForceField(mols[0])
    ff.Initialize()
    ff.Minimize(maxIts=200)

    rmsd = ChemAlign.AlignMol(mols[0], mols[1], atomMap=pyO3A.Matches())
    print('rmsd')
    print(rmsd)

    print('energy')
    print(ff.CalcEnergy())

    # launch pymol in server mode: `./pymol -R`
    # it resides in ~/anaconda/bin
    v = PyMol.MolViewer()
    v.ShowMol(mols[0])
    v.GetPNG(h=200)
コード例 #5
0
def show_axes(mol, confId, mol_coms, conf_axes):
    """
    Show the principal moments of inertia on a single conformation.

    """
    # show the principle axes on one conformer
    try:
        v = PyMol.MolViewer()
    except ConnectionRefusedError:
        print("run 'pymol -R' to visualise structures")
        print('visualisation will be skipped')
    v.server.do('reinitialize')
    v.server.do('delete all')

    # v.DeleteAll()
    v.ShowMol(mol, confId=confId, name='Conf-0', showOnly=False)
    # com
    v.server.sphere(
        list([float(i) for i in mol_coms[confId]]),
        0.2,
        (2, 1, 0),
        'COM'
    )
    # principal axes
    v.server.sphere(
        list([float(i) for i in conf_axes[confId][0, :]]),
        0.2,
        (2, 0, 0),
        'AX1'
    )
    v.server.sphere(
        list([float(i) for i in conf_axes[confId][1, :]]),
        0.2,
        (1, 0, 1),
        'AX2'
    )
    v.server.sphere(
        list([float(i) for i in conf_axes[confId][2, :]]),
        0.2,
        (0, 1, 0),
        'AX3'
    )
    v.GetPNG()
コード例 #6
0
ファイル: analysis.py プロジェクト: abazabaaa/arrow_testing
from rdkit.Chem import AllChem
from rdkit.Chem import rdMolAlign
from rdkit.Chem import rdShapeHelpers
from rdkit.Chem import rdMolDescriptors
from rdkit.Chem import PyMol
from rdkit.Chem import Draw
from rdkit.Chem.Draw import IPythonConsole
import pyarrow as pa
from pyarrow import csv
import pandas as pd
import pyarrow.feather as feather
import copy
from rich import print
import numpy as np
import pandas as pd
v = PyMol.MolViewer()
mols_ref = Chem.SDMolSupplier(
    '/Users/tom/code_test_repository/arrow_testing/cdk2.sdf', removeHs=False)
cdk2mol_ref = [m for m in mols_ref]
cdk2mol_reference = cdk2mol_ref[0]
cdk2mol_reference
df = feather.read_feather(
    '/Users/tom/code_test_repository/arrow_testing/test2.feather')
df = df.sort_values(by=['fps'], ascending=False)
df = df.reset_index(drop=True)
df[['name', 'conf', 'number']] = df.name.str.split('_', expand=True)
d2f = df.drop_duplicates(subset="name", keep="first")

# lis2 = df['fps']
d2f = d2f.reset_index(drop=True)
lis = d2f['mol_blocks']
コード例 #7
0
def get_ellip_diameters(
    mol,
    cids,
    vdwScale=1.0,
    boxMargin=2.0,
    spacing=0.2,
    show=False,
    plot=False,
    do_step_plot=False
):
    """
    Fit an ellipsoid to the points within the VDW cloud of a all
    conformers.

    Keywords:
        mol (RDKIT Molecule) - RDKIT molecule object to calculate
        ellipsoid for
        cids (list) - list of RDKIT conformer IDs of mol
        vdwScale (float) - Scaling factor for the radius of the atoms
        to
            determine the base radius used in the encoding
            - grid points inside this sphere carry the maximum
            occupancy
            default = 1.0 Angstrom
        boxMargin (float) - added margin to grid surrounding molecule
            default=4.0 Angstrom
        spacing (float) - grid spacing - default = 1.0 Angstrom
        show (bool) - show VDW cloud using PYMOL? - default = False
        plot (bool) - show ellipsoid around VDW? - default = False

    Returns:
        conf_diameters (list) - 3 principal diameters of ellipsoids
        for all
            conformers
        conf_axes (list) - 3 principal axes of mol for all conformers
        conf_axes (list) - 3 principal moments of mol for all
        conformers

    """
    # over conformers
    conf_diameters = []
    conf_axes = []
    conf_moments = []
    for confId in cids:
        conf = mol.GetConformer(confId)
        box, sideLen, shape = get_molec_shape(
            mol, conf, confId,
            vdwScale=vdwScale,
            boxMargin=boxMargin,
            spacing=spacing
        )

        if show:
            try:
                v = PyMol.MolViewer()
            except ConnectionRefusedError:
                print("run 'pymol -R' to visualise structures")
                print('visualisation will be skipped')
            show_shape(v, mol, confId, shape)
            v.server.do('set transparency=0.5')

        # get ellipsoid fitting all points with value > 2
        # - i.e. within vdw shape
        hit_points = []
        for idx in range(shape.GetSize()):
            pt = shape.GetGridPointLoc(idx)
            value = shape.GetVal(idx)
            if value > 2:
                point = np.array([pt.x, pt.y, pt.z])
                hit_points.append(point)
        hit_points = np.asarray(hit_points)

        # get inertial properties of conformer
        axes, moments = Chem.ComputePrincipalAxesAndMoments(
            conf,
            ignoreHs=False
        )
        conf_axes.append(axes)
        conf_moments.append(moments)
        # find the ellipsoid that envelopes all hit points
        ET = ellipsoid.EllipsoidTool()
        (center, radii, rotation) = ET.getMinVolEllipse(
            P=hit_points,
            tolerance=0.01,
            do_step_plot=do_step_plot
        )

        conf_diameters.append(sorted(np.asarray(radii)*2))

        # only do plot for the first conformer
        if confId == 0 and plot is True:
            hit_point_plot(
                hit_points,
                ET,
                center,
                radii,
                rotation
            )

    return conf_diameters, conf_axes, conf_moments
コード例 #8
0
def get_vdw_diameters(
    mol,
    cids,
    mol_coms,
    vdwScale=1.0,
    boxMargin=2.0,
    spacing=0.2,
    vec_spacing=0.05,
    show=False,
    plot=False
):
    """Get the extent of the VDW size of each conformer along its
    principle axes.


    """
    # over conformers
    conf_diameters = []
    conf_axes = []
    conf_moments = []
    for confId in cids:
        conf = mol.GetConformer(confId)
        print(confId)
        # try:
        #     Chem.CanonicalizeConformer(conf)
        # except RuntimeError:
        #     pass
        box, sideLen, shape = get_molec_shape(mol, conf, confId,
                                              vdwScale=vdwScale,
                                              boxMargin=boxMargin,
                                              spacing=spacing)
        if show is True:
            try:
                v = PyMol.MolViewer()
            except ConnectionRefusedError:
                print("run 'pymol -R' to visualise structures")
                print('visualisation will be skipped')
            show_shape(v, mol, confId, shape)
            v.server.do('set transparency=0.5')

        # get extent of shape along principle axes
        axes, moments = Chem.ComputePrincipalAxesAndMoments(
            conf,
            ignoreHs=False
        )
        conf_axes.append(axes)
        conf_moments.append(moments)
        sml_PMI, mid_PMI, lge_PMI = moments
        COM = mol_coms[confId]
        com_pt = def_point(*COM)
        # define vector from COM along each principal axis
        max_side_len = max([i*2 for i in sideLen])
        diameters = []
        vectors = []
        vals = []
        for AX in [0, 1, 2]:
            axis = axes[AX, :]
            vector = define_vector(axis, max_side_len, vec_spacing)
            vectors.append(vector)
            values, distances = get_dist_and_values(
                vector,
                com_pt,
                shape
            )
            vals.append(values)
            ind_1, ind_2 = get_boundary_idx(values)
            print(ind_1, ind_2)
            if ind_1 is not None or ind_2 is not None:
                diameter = distances[ind_1] + distances[ind_2]
                diameters.append(diameter)
            else:
                try:
                    v = PyMol.MolViewer()
                except ConnectionRefusedError:
                    print("run 'pymol -R' to visualise structures")
                    print('visualisation will be skipped')
                show_shape(v, mol, confId, shape)
                print(max_side_len)
                print(com_pt)
                print(axis)
                v.server.do('set transparency=0.5')
                v.server.sphere(
                    list([
                        float(i) for i in com_pt
                    ]), 0.2, (2, 1, 0), 'COM'
                )
                # principal axes
                v.server.sphere(
                    list([
                        float(i) for i in axis
                    ]), 0.2, (2, 0, 0), 'AX'
                )
                import sys
                sys.exit()
        if len(diameters) == 3:
            conf_diameters.append(diameters)

        # only do plot for the first conformer
        if confId == 0 and plot is True:
            try:
                v = PyMol.MolViewer()
            except ConnectionRefusedError:
                pass
            show_shape(v, mol, confId, shape)
            v.server.do('set transparency=0.5')
            v.server.sphere(
                list(
                    [float(i) for i in mol_coms[confId]]
                ), 0.2, (2, 1, 0), 'COM'
            )
            # principal axes
            v.server.sphere(
                list(
                    [float(i) for i in conf_axes[confId][0, :]]
                ), 0.2, (2, 0, 0), 'AX1'
            )
            v.server.sphere(
                list(
                    [float(i) for i in conf_axes[confId][1, :]]
                ), 0.2, (1, 0, 1), 'AX2'
            )
            v.server.sphere(
                list(
                    [float(i) for i in conf_axes[confId][2, :]]
                ), 0.2, (0, 1, 0), 'AX3'
            )
            for ax in [0, 1, 2]:
                for i, vec in enumerate(vectors[ax]):
                    if vals[ax][i] <= 2:
                        C = (1, 1, 1)
                    else:
                        C = (1, 0, 0)
                    v.server.sphere(
                        list([float(i) for i in vec]), 0.05, C, 'pt'
                    )

    return conf_diameters, conf_axes, conf_moments