Example #1
0
    def load_coords_pymol(self, coordslist, oname, index=1):
        """load the coords into pymol
        
        the new object must be named oname so we can manipulate it later
                        
        Parameters
        ----------
        coordslist : list of arrays
        oname : str
            the new pymol object must be named oname so it can be manipulated
            later
        index : int
            we can have more than one molecule on the screen at one time.  index tells
            which one to draw.  They are viewed at the same time, so should be
            visually distinct, e.g. different colors.  accepted values are 1 or 2
        
        Notes
        -----
        the implementation here is a bit hacky.  we create a temporary xyz file from coords
        and load the molecule in pymol from this file.  
        """
        #pymol is imported here so you can do, e.g. basinhopping without installing pymol
        import pymol

        #create the temporary file
        suffix = ".xyz"
        f = tempfile.NamedTemporaryFile(mode="w", suffix=suffix)
        fname = f.name

        #write the coords into the xyz file
        from pygmin.mindist import CoMToOrigin
        for coords in coordslist:
            coords = CoMToOrigin(coords.copy())
            write_xyz(f, coords, title=oname, atomtypes=["LA"])
        f.flush()

        #load the molecule from the temporary file
        pymol.cmd.load(fname)

        #get name of the object just create and change it to oname
        objects = pymol.cmd.get_object_list()
        objectname = objects[-1]
        pymol.cmd.set_name(objectname, oname)

        #set the representation
        pymol.cmd.hide("everything", oname)
        pymol.cmd.show("spheres", oname)

        #set the color according to index
        if index == 1:
            pymol.cmd.color("red", oname)
        else:
            pymol.cmd.color("gray", oname)
Example #2
0
    def load_coords_pymol(self, coordslist, oname, index=1):
        """load the coords into pymol
        
        the new object must be named oname so we can manipulate it later
                        
        Parameters
        ----------
        coordslist : list of arrays
        oname : str
            the new pymol object must be named oname so it can be manipulated
            later
        index : int
            we can have more than one molecule on the screen at one time.  index tells
            which one to draw.  They are viewed at the same time, so should be
            visually distinct, e.g. different colors.  accepted values are 1 or 2
        
        Notes
        -----
        the implementation here is a bit hacky.  we create a temporary xyz file from coords
        and load the molecule in pymol from this file.  
        """
        #pymol is imported here so you can do, e.g. basinhopping without installing pymol
        import pymol 

        #create the temporary file
        suffix = ".xyz"
        f = tempfile.NamedTemporaryFile(mode="w", suffix=suffix)
        fname = f.name
                
        #write the coords into the xyz file
        from pygmin.mindist import CoMToOrigin
        for coords in coordslist:
            coords = CoMToOrigin(coords.copy())
            write_xyz(f, coords, title=oname, atomtypes=["LA"])
        f.flush()
                
        #load the molecule from the temporary file
        pymol.cmd.load(fname)
        
        #get name of the object just create and change it to oname
        objects = pymol.cmd.get_object_list()
        objectname = objects[-1]
        pymol.cmd.set_name(objectname, oname)
        
        #set the representation
        pymol.cmd.hide("everything", oname)
        pymol.cmd.show("spheres", oname)
        
        #set the color according to index
        if index == 1:
            pymol.cmd.color("red", oname)
        else:
            pymol.cmd.color("gray", oname)
Example #3
0
    def load_coords_pymol(self, coordslist, oname, index=1):
        """load the coords into pymol
        
        the new object must be named oname so we can manipulate it later
                        
        Parameters
        ----------
        coordslist : list of arrays
        oname : str
            the new pymol object must be named oname so it can be manipulated
            later
        index : int
            we can have more than one molecule on the screen at one time.  index tells
            which one to draw.  They are viewed at the same time, so they should be
            visually distinct, e.g. different colors.  accepted values are 1 or 2
        
        Notes
        -----
        the implementation here is a bit hacky.  we create a temporary xyz file from coords
        and load the molecule in pymol from this file.  
        """
        #pymol is imported here so you can do, e.g. basinhopping without installing pymol
        import pymol

        #create the temporary file (.xyz or .pdb, or whatever else pymol can read)
        #note: this is the part that will be really system dependent.
        f = tempfile.NamedTemporaryFile(mode="w", suffix=".xyz")
        fname = f.name
        #write the coords into file
        for coords in coordslist:
            write_xyz(f, coords, title=oname)
        f.flush()

        #load the molecule from the temporary file
        pymol.cmd.load(fname)

        #get name of the object just create and change it to oname
        objects = pymol.cmd.get_object_list()
        objectname = objects[-1]
        pymol.cmd.set_name(objectname, oname)

        #here you might want to change the representation of the molecule, e.g.
        # >>> pymol.cmd.hide("everything", oname)
        # >>> pymol.cmd.show("spheres", oname)

        #set the color according to index
        if index == 1:
            pymol.cmd.color("red", oname)
        else:
            pymol.cmd.color("gray", oname)
Example #4
0
    def load_coords_pymol(self, coordslist, oname, index=1):
        """load the coords into pymol
        
        the new object must be named oname so we can manipulate it later
                        
        Parameters
        ----------
        coordslist : list of arrays
        oname : str
            the new pymol object must be named oname so it can be manipulated
            later
        index : int
            we can have more than one molecule on the screen at one time.  index tells
            which one to draw.  They are viewed at the same time, so they should be
            visually distinct, e.g. different colors.  accepted values are 1 or 2
        
        Notes
        -----
        the implementation here is a bit hacky.  we create a temporary xyz file from coords
        and load the molecule in pymol from this file.  
        """
        #pymol is imported here so you can do, e.g. basinhopping without installing pymol
        import pymol 

        #create the temporary file (.xyz or .pdb, or whatever else pymol can read)
        #note: this is the part that will be really system dependent.        
        f = tempfile.NamedTemporaryFile(mode="w", suffix=".xyz")
        fname = f.name
        #write the coords into file
        for coords in coordslist:
            write_xyz(f, coords, title=oname)
        f.flush()
                
        #load the molecule from the temporary file
        pymol.cmd.load(fname)
        
        #get name of the object just create and change it to oname
        objects = pymol.cmd.get_object_list()
        objectname = objects[-1]
        pymol.cmd.set_name(objectname, oname)
        
        #here you might want to change the representation of the molecule, e.g.
        # >>> pymol.cmd.hide("everything", oname)
        # >>> pymol.cmd.show("spheres", oname)
        
        #set the color according to index
        if index == 1:
            pymol.cmd.color("red", oname)
        else:
            pymol.cmd.color("gray", oname)
Example #5
0
Example 3: Saving all minima found to an xyz file
"""
from pygmin.systems import LJCluster
from pygmin.utils.xyz import write_xyz

natoms = 12
niter = 100
system = LJCluster(natoms)

db = system.create_database()
bh = system.get_basinhopping(database=db)
bh.run(niter)

with open("lowest", "w") as fout:
    for minimum in db.minima():
        title = "energy = ", str(minimum.energy)
        write_xyz(fout, minimum.coords, title)

############################################################
# some visualization
############################################################
try:
    import pygmin.utils.pymolwrapper as pym
    pym.start()
    frame = 1
    for minimum in db.minima():
        pym.draw_spheres(minimum.coords.reshape(-1, 3), "A", frame)
        frame = frame + 1
except:
    print "Could not draw using pymol, skipping this step"
Example #6
0
import numpy as np
from pygmin.potentials import LJ
from pygmin.utils import xyz
from pygmin.angleaxis import rigidbody
from pygmin.optimize import lbfgs_py

# read in coordinates from xyz file
ref = xyz.read_xyz(open("water.xyz"))
xyz.write_xyz(open("test.xyz", "w"), coords = ref.coords)
# lookup table for atom masses
mass_lookup = {'O': 16., 'H': 1.}

#ref.coords[:] *= 3

# now define a new rigid body system
rb_sites = []
for atomtype, x, i in zip(ref.atomtypes, ref.coords, xrange(len(ref.atomtypes))):
    # every 3rd atom, define a new reigid molecule
    if i%3 == 0:
        rb = rigidbody.RigidFragment()
        rb_sites.append(rb)                
    rb.add_atom(atomtype, x, mass_lookup[atomtype])

# finalize the rigid body setup
for rb in rb_sites:
    rb.finalize_setup()

# define a new rigid body system    
rbsystem = rigidbody.RBSystem()
rbsystem.add_sites(rb_sites)
Example #7
0
import numpy as np
from pygmin.potentials import LJ
from pygmin.utils import xyz
from pygmin.angleaxis import rigidbody
from pygmin.optimize import lbfgs_py

# read in coordinates from xyz file
ref = xyz.read_xyz(open("water.xyz"))
xyz.write_xyz(open("test.xyz", "w"), coords = ref.coords)
# lookup table for atom masses
mass_lookup = {'O': 16., 'H': 1.}

#ref.coords[:] *= 3

# now define a new rigid body system
rb_sites = []
for atomtype, x, i in zip(ref.atomtypes, ref.coords, xrange(len(ref.atomtypes))):
    # every 3rd atom, define a new reigid molecule
    if i%3 == 0:
        rb = rigidbody.RigidFragment()
        rb_sites.append(rb)                
    rb.add_atom(atomtype, x, mass_lookup[atomtype])

# finalize the rigid body setup
for rb in rb_sites:
    rb.finalize_setup()

# define a new rigid body system    
rbsystem = rigidbody.RBSystem()
rbsystem.add_sites(rb_sites)
Example #8
0
    def load_coords_pymol(self, coordslist, oname, index=1):
        """load the coords into pymol
        
        the new object must be named oname so we can manipulate it later
                        
        Parameters
        ----------
        coordslist : list of arrays
        oname : str
            the new pymol object must be named oname so it can be manipulated
            later
        index : int
            we can have more than one molecule on the screen at one time.  index tells
            which one to draw.  They are viewed at the same time, so should be
            visually distinct, e.g. different colors.  accepted values are 1 or 2
        
        Notes
        -----
        the implementation here is a bit hacky.  we create a temporary xyz file from coords
        and load the molecule in pymol from this file.  
        """
        # pymol is imported here so you can do, e.g. basinhopping without installing pymol
        import pymol 

        # create the temporary file
        suffix = ".xyz"
        f = tempfile.NamedTemporaryFile(mode="w", suffix=suffix)
        fname = f.name
                
        # write the atomistic coords into the xyz file
        from pygmin.mindist import CoMToOrigin
        for coords in coordslist:
            if hasattr(self, "atom_types"):
                atom_types = self.atom_types
            else:
                atom_types = ["O"]
            atom_coords = self.aasystem.to_atomistic(coords)
            write_xyz(f, atom_coords, title=oname, atomtypes=atom_types)
        f.flush()
                
        # load the molecule from the temporary file into pymol
        pymol.cmd.load(fname)
        
        # get name of the object just create and change it to oname
        objects = pymol.cmd.get_object_list()
        objectname = objects[-1]
        pymol.cmd.set_name(objectname, oname)
        
        # set the representation as spheres
        pymol.cmd.hide("everything", oname)
        pymol.cmd.show("spheres", oname)

        # draw the bonds
        if hasattr(self, "draw_bonds"):
            pymol.cmd.unbond(oname, oname)
            for i1, i2 in self.draw_bonds:
                pymol.cmd.bond("id %d and %s" % (i1+1, oname), 
                               "id %d and %s" % (i2+1, oname))
            pymol.cmd.show("lines", oname)

        # set the color of index 2 so they appear different
        if index == 2:
            pymol.cmd.color("gray", oname)
Example #9
0
Example 3: Saving all minima found to an xyz file
"""
from pygmin.systems import LJCluster
from pygmin.utils.xyz import write_xyz

natoms = 12
niter = 100
system = LJCluster(natoms)

db = system.create_database()
bh = system.get_basinhopping(database=db)
bh.run(niter)

with open("lowest", "w") as fout:
    for minimum in db.minima():
        title = "energy = ", str(minimum.energy)
        write_xyz(fout, minimum.coords, title)
           
############################################################
# some visualization
############################################################
try: 
    import pygmin.utils.pymolwrapper as pym
    pym.start()
    frame=1  
    for minimum in db.minima():        
        pym.draw_spheres(minimum.coords.reshape(-1, 3), "A", frame)
        frame=frame+1
except:
    print "Could not draw using pymol, skipping this step"