示例#1
0
 def testFit(self):
     cmd.fragment("gly", "m1")
     cmd.create("m2", "m1")
     rms = cmd.fit("m1", "m2")
     self.assertEqual(rms, 0.0)
     rms = cmd.rms("m1", "m2")
     self.assertEqual(rms, 0.0)
     rms = cmd.rms_cur("m1", "m2")
     self.assertEqual(rms, 0.0)
示例#2
0
 def testFit(self):
     cmd.fragment("gly", "m1")
     cmd.create("m2", "m1")
     rms = cmd.fit("m1", "m2")
     self.assertEqual(rms, 0.0)
     rms = cmd.rms("m1", "m2")
     self.assertEqual(rms, 0.0)
     rms = cmd.rms_cur("m1", "m2")
     self.assertEqual(rms, 0.0)
示例#3
0
def conf_search(selection='all', forcefield='MMFF94s', method='Weighted', nsteps=500, conformers=25, lowest_conf=5):
    pdb_string = cmd.get_pdbstr(selection)
    name = cmd.get_legal_name(selection)
    obconversion = ob.OBConversion()
    obconversion.SetInAndOutFormats('pdb', 'pdb')
    mol = ob.OBMol()
    obconversion.ReadString(mol, pdb_string)
    mol.AddHydrogens()
    ff = ob.OBForceField.FindForceField(forcefield)  # GAFF, MMFF94s, MMFF94, UFF, Ghemical
    ff.Setup(mol)
    if method == 'Weighted':
        ff.WeightedRotorSearch(conformers, nsteps)
    elif method == 'Random':
        ff.RandomRotorSearch(conformers, nsteps)
    else:
        ff.SystematicRotorSearch(nsteps)
    if name == 'all':
        name = 'all_'
    if method in ['Weighted', 'Random']:
        ff.GetConformers(mol)
        print '##############################################'
        print '   Conformer    |         Energy      |  RMSD'
        nrg_unit = ff.GetUnit()
        rmsd = 0
        ff.GetCoordinates(mol)
        nrg = ff.Energy()
        conf_list = []
        for i in range(conformers):
            mol.SetConformer(i)
            ff.Setup(mol)
            nrg = ff.Energy()
            conf_list.append((nrg, i))
        conf_list.sort()
        lenght_conf_list = len(conf_list)
        if lowest_conf > lenght_conf_list:
            lowest_conf = lenght_conf_list
        for i in range(lowest_conf):
            nrg, orden = conf_list[i]
            name_n = '%s%02d' % (name, i)
            cmd.delete(name_n)
            mol.SetConformer(orden)
            pdb_string = obconversion.WriteString(mol)
            cmd.read_pdbstr(pdb_string, name_n)
            if i != 0:
                rmsd = cmd.fit(name_n, '%s00' % name, quiet=1)
            print '%15s | %10.2f%9s |%6.1f' % (name_n, nrg, nrg_unit, rmsd)
        print '##############################################'
    else:
        ff.GetCoordinates(mol)
        nrg = ff.Energy()
        pdb_string = obconversion.WriteString(mol)
        cmd.delete(name)
        cmd.read_pdbstr(pdb_string, name)
        print '#########################################'
        print 'The Energy of %s is %8.2f %s       ' % (name, nrg, ff.GetUnit())
        print '#########################################'
示例#4
0
def conf_search(selection="all", forcefield="MMFF94s", method="Weighted", nsteps=500, conformers=25, lowest_conf=5):
    pdb_string = cmd.get_pdbstr(selection)
    name = cmd.get_legal_name(selection)
    obconversion = ob.OBConversion()
    obconversion.SetInAndOutFormats("pdb", "pdb")
    mol = ob.OBMol()
    obconversion.ReadString(mol, pdb_string)
    mol.AddHydrogens()
    ff = ob.OBForceField.FindForceField(forcefield)  ## GAFF, MMFF94s, MMFF94, UFF, Ghemical
    ff.Setup(mol)
    if method == "Weighted":
        ff.WeightedRotorSearch(conformers, nsteps)
    elif method == "Random":
        ff.RandomRotorSearch(conformers, nsteps)
    else:
        ff.SystematicRotorSearch(nsteps)
    if name == "all":
        name = "all_"
    if method in ["Weighted", "Random"]:
        ff.GetConformers(mol)
        print "##############################################"
        print "   Conformer    |         Energy      |  RMSD"
        nrg_unit = ff.GetUnit()
        rmsd = 0
        ff.GetCoordinates(mol)
        nrg = ff.Energy()
        conf_list = []
        for i in range(conformers):
            mol.SetConformer(i)
            ff.Setup(mol)
            nrg = ff.Energy()
            conf_list.append((nrg, i))
        conf_list.sort()
        lenght_conf_list = len(conf_list)
        if lowest_conf > lenght_conf_list:
            lowest_conf = lenght_conf_list
        for i in range(lowest_conf):
            nrg, orden = conf_list[i]
            name_n = "%s%02d" % (name, i)
            cmd.delete(name_n)
            mol.SetConformer(orden)
            pdb_string = obconversion.WriteString(mol)
            cmd.read_pdbstr(pdb_string, name_n)
            if i != 0:
                rmsd = cmd.fit(name_n, "%s00" % name, quiet=1)
            print "%15s | %10.2f%9s |%6.1f" % (name_n, nrg, nrg_unit, rmsd)
        print "##############################################"
    else:
        ff.GetCoordinates(mol)
        nrg = ff.Energy()
        pdb_string = obconversion.WriteString(mol)
        cmd.delete(name)
        cmd.read_pdbstr(pdb_string, name)
        print "#########################################"
        print "The Energy of %s is %8.2f %s       " % (name, nrg, ff.GetUnit())
        print "#########################################"
def RenderImage(files, index, reference, OutDir):
    """This function issues commands to pymol. Alter these commands to change
    what the final output looks like. Note that 'reference' is a reference structure
    that allows you to align everything to that structure"""

    cmd.do('reinitialize')
    cmd.do('set_color lblue= [0.86 , 1.00 , 1.00]')

    for i,f in enumerate(files):
        cmd.load(f, 'Structure%d'%i)
    cmd.load(f, 'Overlay')
    cmd.load(reference, 'Reference')

    cmd.hide('all')
    cmd.do('dss')
    cmd.do('bg white')
    
    cmd.do('show cartoon, Overlay')
    cmd.fit('Overlay', 'Reference')

    cmd.fit('Structure0', 'Reference')
    for i in range(len(files)):
        cmd.do('show cartoon, Structure%d'%i)
        cmd.fit('Structure%d'%i, 'Structure0')
        cmd.do('color lblue, Structure%d'%i)
        cmd.do('set cartoon_transparency, 0.5, Structure%d'%i)
    cmd.do('spectrum count, rainbow, Overlay')
    cmd.do('translate [0,0,10], Overlay')

    cmd.do('ray')
    cmd.do('png %s/State%d'% (OutDir, index))

    return
示例#6
0
    def testCreate(self):
        cmd.fragment("ala")
        cmd.create("foo", "ala", 1, 1)

        names = cmd.get_names()
        names.sort()

        self.assertEquals(names, ["ala", "foo"])
        
        # TODO: Create a function to compare to chempy models
        # m1 = cmd.get_model("foo")
        # m2 = cmd.get_model("ala")
        # self.assertChempyModelEquals(m1, m2)

        self.assertEquals(cmd.fit("ala", "foo"), 0.0)

        self.assertEquals(cmd.count_states(), 1)
示例#7
0
    def testCreate(self):
        cmd.fragment("ala")
        cmd.create("foo", "ala", 1, 1)

        names = cmd.get_names()
        names.sort()

        self.assertEquals(names, ["ala", "foo"])
        
        # TODO: Create a function to compare to chempy models
        # m1 = cmd.get_model("foo")
        # m2 = cmd.get_model("ala")
        # self.assertChempyModelEquals(m1, m2)

        self.assertEquals(cmd.fit("ala", "foo"), 0.0)

        self.assertEquals(cmd.count_states(), 1)
def fitting(obj1, select1, obj2, select2):
    """
DESCRIPTION

  "fitting" allows the superpositioning of object1 onto object2 using
  the atoms in selection1 and selection2 (side chains are ignored).  The
  residue names, residue numbers chain identifiers, segment identifiers,
  and alt ids of selection1 are changed to match those in selection2,
  temporarily.  This allows the normal "fit" command to work.  They are
  reset after "fit" is run and two new selections are created showing
  the selected atoms.

  Be careful when creating your selection strings. Within the
  selections, do not include the object name because the chain, residue
  name, residue number etc. of selection1 of object1 are converted to
  match those in selection2.  If the object names are included in the
  selections, no atoms will be selected since an atom cannot exist in
  both object1 and object2 at the same time.

  It is important that the beginning residue numbers specify the
  aligned residues, but the ending numbers are not critical.  The
  shorter of the two selections is used in the fit calculation.

USAGE

  fitting object1, selection1, object2, selection2

  DO NOT include object names in selections!

EXAMPLES

  fitting 1xuu, c. a & (i. 296-309 or i. 335-340), 1ame, i. 8-21 or i. 47-52

  """

    list_m = []
    list_n = []

    backbone = "n. n+ca+c+o &! r. hoh+wat"
    select1 = "(%s) & %s" % (select1, backbone)
    select2 = "(%s) & %s" % (select2, backbone)
    m = cmd.get_model("%s & %s" % (obj1, select1))
    n = cmd.get_model("%s & %s" % (obj2, select2))

    # for the atoms to be used in fit:
    # store id, chain, resn, resi, name, segi, alt
    for at in m.atom:
        list_m.append((at.id, at.chain, at.resn, at.resi, at.name, at.segi, at.alt))
    for at in n.atom:
        list_n.append((at.id, at.chain, at.resn, at.resi, at.name, at.segi, at.alt))

    if len(m.atom) <= len(n.atom):
        total = len(m.atom)
    else:
        total = len(n.atom)

    # set a new segi for the atoms to be used in fit command and to allow resetting later
    seg_fit = "1fit"

    # change the chain,resn,resi,segi and alt of select1 to match select2
    for i in range(total):
        cmd.do("alter %s & id %s, chain='%s'" % (obj1, list_m[i][0], list_n[i][1]))
        cmd.do("alter %s & id %s, resn='%s'" % (obj1, list_m[i][0], list_n[i][2]))
        cmd.do("alter %s & id %s, resi=%s" % (obj1, list_m[i][0], list_n[i][3]))
        cmd.do("alter %s & id %s, segi='%s'" % (obj1, list_m[i][0], seg_fit))
        cmd.do("alter %s & id %s, alt='%s'" % (obj1, list_m[i][0], list_n[i][6]))
        # change the segid for obj2 and select2
        cmd.do("alter %s & id %s, segi='%s'" % (obj2, list_n[i][0], seg_fit))

    print "Fitting %s and %s\n     to %s and %s" % (obj1, select1, obj2, select2)

    print "Altered to:"
    print "%s & %s & segi %s\n" % (obj1, select2, seg_fit),
    print "%s & %s & segi %s\n" % (obj2, select2, seg_fit),
    print "--------------------------------------------\n"
    rms = cmd.fit(
        "%s & %s & segi %s" % (obj1, select2, seg_fit), "%s & %s & segi %s" % (obj2, select2, seg_fit), quiet=0
    )

    cmd.delete("%s_fitting" % obj1)
    cmd.delete("%s_fitting" % obj2)
    # create new objects to show the fit atoms
    cmd.create("%s_fitting" % obj1, "%s & %s & segi %s" % (obj1, select2, seg_fit))
    cmd.create("%s_fitting" % obj2, "%s & %s & segi %s" % (obj2, select2, seg_fit))

    # reset chain,resn,resi,segi & alt of obj1 & select1 from stored list
    for atoms_m in list_m:
        cmd.do("alter %s & id %s, chain='%s'" % (obj1, atoms_m[0], atoms_m[1]))
        cmd.do("alter %s & id %s, resn='%s'" % (obj1, atoms_m[0], atoms_m[2]))
        cmd.do("alter %s & id %s, resi=%s" % (obj1, atoms_m[0], atoms_m[3]))
        cmd.do("alter %s & id %s, segi='%s'" % (obj1, atoms_m[0], atoms_m[5]))
        cmd.do("alter %s & id %s, alt='%s'" % (obj1, atoms_m[0], atoms_m[6]))
    # reset segi of obj2 & select2 from stored list
    for atoms_n in list_n:
        cmd.do("alter %s & id %s, segi='%s'" % (obj2, atoms_n[0], atoms_n[5]))

    print "RMSD for fitting selection %s of %s onto \n                 selection %s of %s = %6.3f" % (
        select1,
        obj1,
        select2,
        obj2,
        rms,
    )
示例#9
0
def fitting(obj1, select1, obj2, select2):
    """
DESCRIPTION

  "fitting" allows the superpositioning of object1 onto object2 using
  the atoms in selection1 and selection2 (side chains are ignored).  The
  residue names, residue numbers chain identifiers, segment identifiers,
  and alt ids of selection1 are changed to match those in selection2,
  temporarily.  This allows the normal "fit" command to work.  They are
  reset after "fit" is run and two new selections are created showing
  the selected atoms.

  Be careful when creating your selection strings. Within the
  selections, do not include the object name because the chain, residue
  name, residue number etc. of selection1 of object1 are converted to
  match those in selection2.  If the object names are included in the
  selections, no atoms will be selected since an atom cannot exist in
  both object1 and object2 at the same time.

  It is important that the beginning residue numbers specify the
  aligned residues, but the ending numbers are not critical.  The
  shorter of the two selections is used in the fit calculation.

USAGE

  fitting object1, selection1, object2, selection2

  DO NOT include object names in selections!

EXAMPLES

  fitting 1xuu, c. a & (i. 296-309 or i. 335-340), 1ame, i. 8-21 or i. 47-52

  """

    list_m = []
    list_n = []

    backbone = 'n. n+ca+c+o &! r. hoh+wat'
    select1 = '(%s) & %s' % (select1, backbone)
    select2 = '(%s) & %s' % (select2, backbone)
    m = cmd.get_model("%s & %s" % (obj1, select1))
    n = cmd.get_model("%s & %s" % (obj2, select2))

    # for the atoms to be used in fit:
    # store id, chain, resn, resi, name, segi, alt
    for at in m.atom:
        list_m.append(
            (at.id, at.chain, at.resn, at.resi, at.name, at.segi, at.alt))
    for at in n.atom:
        list_n.append(
            (at.id, at.chain, at.resn, at.resi, at.name, at.segi, at.alt))

    if len(m.atom) <= len(n.atom):
        total = len(m.atom)
    else:
        total = len(n.atom)

# set a new segi for the atoms to be used in fit command and to allow resetting later
    seg_fit = "1fit"

    # change the chain,resn,resi,segi and alt of select1 to match select2
    for i in range(total):
        cmd.do("alter %s & id %s, chain='%s'" %
               (obj1, list_m[i][0], list_n[i][1]))
        cmd.do("alter %s & id %s, resn='%s'" %
               (obj1, list_m[i][0], list_n[i][2]))
        cmd.do("alter %s & id %s, resi=%s" %
               (obj1, list_m[i][0], list_n[i][3]))
        cmd.do("alter %s & id %s, segi='%s'" % (obj1, list_m[i][0], seg_fit))
        cmd.do("alter %s & id %s, alt='%s'" %
               (obj1, list_m[i][0], list_n[i][6]))
        # change the segid for obj2 and select2
        cmd.do("alter %s & id %s, segi='%s'" % (obj2, list_n[i][0], seg_fit))

    print "Fitting %s and %s\n     to %s and %s" % (obj1, select1, obj2,
                                                    select2)

    print "Altered to:"
    print "%s & %s & segi %s\n" % (obj1, select2, seg_fit),
    print "%s & %s & segi %s\n" % (obj2, select2, seg_fit),
    print "--------------------------------------------\n"
    rms = cmd.fit("%s & %s & segi %s" % (obj1, select2, seg_fit),
                  "%s & %s & segi %s" % (obj2, select2, seg_fit),
                  quiet=0)

    cmd.delete("%s_fitting" % obj1)
    cmd.delete("%s_fitting" % obj2)
    # create new objects to show the fit atoms
    cmd.create("%s_fitting" % obj1,
               "%s & %s & segi %s" % (obj1, select2, seg_fit))
    cmd.create("%s_fitting" % obj2,
               "%s & %s & segi %s" % (obj2, select2, seg_fit))

    # reset chain,resn,resi,segi & alt of obj1 & select1 from stored list
    for atoms_m in list_m:
        cmd.do("alter %s & id %s, chain='%s'" % (obj1, atoms_m[0], atoms_m[1]))
        cmd.do("alter %s & id %s, resn='%s'" % (obj1, atoms_m[0], atoms_m[2]))
        cmd.do("alter %s & id %s, resi=%s" % (obj1, atoms_m[0], atoms_m[3]))
        cmd.do("alter %s & id %s, segi='%s'" % (obj1, atoms_m[0], atoms_m[5]))
        cmd.do("alter %s & id %s, alt='%s'" % (obj1, atoms_m[0], atoms_m[6]))


# reset segi of obj2 & select2 from stored list
    for atoms_n in list_n:
        cmd.do("alter %s & id %s, segi='%s'" % (obj2, atoms_n[0], atoms_n[5]))

    print "RMSD for fitting selection %s of %s onto \n                 selection %s of %s = %6.3f" % (
        select1, obj1, select2, obj2, rms)
示例#10
0
print "the 1st random number should be %8.3f\notherwise the rest of the test is meaningless...\n" % pymol.random()

pymol.random = random

cmd.load("dat/pept.pdb", "ref")

for a in xrange(1, 11):
    cmd.create("trg", "ref", 1, a, quiet=0)
    cmd.alter_state(a, "trg", "x=x+random()/2")
    cmd.alter_state(a, "trg", "y=y+random()/2")
    cmd.alter_state(a, "trg", "z=z+random()/2", quiet=0)


cmd.frame(1)
print "%8.3f" % cmd.fit("ref", "trg")

# asdf


for a in xrange(1, 14):
    print a,
    print "%8.3f" % cmd.fit("ref and resi %d" % a, "trg"),
    print "%8.3f" % cmd.rms("ref", "trg"),
    print "%8.3f" % cmd.rms_cur("ref", "trg")

cmd.frame(10)

print "%8.3f" % cmd.fit("ref", "trg")
for a in xrange(1, 14):
    print a,
print "the 1st random number should be %8.3f\notherwise the rest of the test is meaningless...\n" % pymol.random(
)

pymol.random = random

cmd.load("dat/pept.pdb", "ref")

for a in xrange(1, 11):
    cmd.create("trg", "ref", 1, a, quiet=0)
    cmd.alter_state(a, "trg", "x=x+random()/2")
    cmd.alter_state(a, "trg", "y=y+random()/2")
    cmd.alter_state(a, "trg", "z=z+random()/2", quiet=0)

cmd.frame(1)
print "%8.3f" % cmd.fit("ref", "trg")

# asdf

for a in xrange(1, 14):
    print a,
    print "%8.3f" % cmd.fit("ref and resi %d" % a, "trg"),
    print "%8.3f" % cmd.rms("ref", "trg"),
    print "%8.3f" % cmd.rms_cur("ref", "trg")

cmd.frame(10)

print "%8.3f" % cmd.fit("ref", "trg")
for a in xrange(1, 14):
    print a,
    print "%8.3f" % cmd.fit("ref and resi %d" % a, "trg"),