Exemplo n.º 1
0
def vmd_load_molecule(coordsfile,
                      filetype="lammpsdata",
                      dcd=None,
                      selection="all",
                      scale=1.0,
                      molid=0,
                      vmd_material="Basic1Pantone",
                      style="CPK 1.000000 0.300000 12.000000 12.000000"):
    """
    """
    if not molecule.exists(molid):

        # load molecule in vmd
        if dcd is not None:
            molecule.load(filetype, coordsfile, "dcd", dcd)
        else:
            molecule.load(filetype, coordsfile)

        molrep.modrep(molid,
                      0,
                      style=style,
                      material=vmd_material,
                      color="Name",
                      sel=selection)
        #trans.scale(scale)
        VMD.evaltcl("scale to {}".format(scale))
Exemplo n.º 2
0
def vmd_prepare_scene():
    """Change the lighting and background so it is the same for each image when rendering."""
    VMD.evaltcl("light 1 off")
    VMD.evaltcl("display shadows off")
    color_display = color.get_colormap("Display")
    color_display["Background"] = "white"
    color.set_colormap("Display", color_display)
    display.set(depthcue=0)
    display.update()
    display.update_ui()
Exemplo n.º 3
0
def vmd_render_scene(image_out,
                     image_size=[2000, 2000],
                     renderer="TachyonLOptiXInternal",
                     frame_idx=0):
    """
    Render the image using renderer with resolution image_size.
    """
    disp_default_size = display.get("size")
    # higher resolution
    display.set(size=image_size)
    display.update()
    display.update_ui()
    VMD.evaltcl("light 0 off")
    render.render(renderer, "{}.ppm".format(image_out))
    VMD.evaltcl("light 0 on")
    image = Image.open("{}.ppm".format(image_out))
    image.save("{}.png".format(image_out), format="PNG")
    #display.set(size=disp_default_size)
    display.update()
    display.update_ui()
    os.remove("{}.ppm".format(image_out))
Exemplo n.º 4
0
def main():
    options, args = PARSER.parse_args()

    if len(args) != 2:
        sys.stderr.write("This script requires exactly 2 arguments.")
        quit(1)

    forward, backward = args
    output = os.path.abspath(options.output)

    forward = os.path.abspath(forward)
    backward = os.path.abspath(backward)
    if not os.path.isdir(output):
        os.mkdir(output)
    os.chdir(output)

    forward = fix_fepout(forward, output)
    backward = fix_fepout(backward, output)

    VMD.evaltcl('package require parsefep')
    VMD.evaltcl('parsefep -forward %s -backward %s -bar' % (forward, backward))
    quit()
Exemplo n.º 5
0
MDFF_POTENTIAL = 'mdff-potential.dx'
MDFF_WEIGHTS = 'mdff-weights.pdb'
MDFF_CONSTRAINT_HBONDS = 'mdff-hbonds.dat'
MDFF_CONSTRAINT_CISPEPTIDE = 'mdff-cispeptide.dat'
MDFF_CONSTRAINT_CHIRALITY = 'mdff-chirality.dat'

model = Molecule.create()
model.load(PSF)
model.load(PDB)

template = Molecule.create()
template.load(MDFF_TEMPLATE_PSF)
template.load(MDFF_TEMPLATE_PDB)

# Load mdff
VMD.evaltcl('package require mdff')
# Generate simulated MDFF map
VMD.evaltcl('mdff sim [atomselect {molid} protein] -res 5 -o {outfile}'.format(
    molid=template.molid, outfile=MDFF_MAP))
# Convert map to potential
VMD.evaltcl('mdff griddx -i {infile} -o {outfile}'.format(
    infile=MDFF_MAP, outfile=MDFF_POTENTIAL))
# Generate scaling factors
VMD.evaltcl('mdff gridpdb -psf {psf} -pdb {pdb} -o {outfile}'.format(
    psf=PSF, pdb=PDB, outfile=MDFF_WEIGHTS))

# Generate additional constraints to prevent overfitting

# Prepare secondary structure restraints
VMD.evaltcl('package require ssrestraints')
VMD.evaltcl('ssrestraints -psf {psf} -pdb {pdb} -o {outfile} -hbonds'.format(
Exemplo n.º 6
0
from pyvmd.atoms import Selection
from pyvmd.molecules import Molecule, FORMAT_PDB, FORMAT_PSF

TEMPLATE_PDB = '../structures/3j5p.pdb'
TMP_DIR = tempfile.mkdtemp(prefix='vmd_')
TOPOLOGY = '/usr/lib/vmd/plugins/noarch/tcl/readcharmmtop1.1/top_all27_prot_lipid_na.inp'

# Load template
template = Molecule.create()
template.load(TEMPLATE_PDB)

# Center the template
center = measure.center(Selection('all', template))
Selection('all', template).atomsel.moveby((-center[0], -center[1], -center[2]))
# Rotate the template, so model takes less space
VMD.evaltcl('[atomselect %d all] move [transaxis z -35]' % template.molid)

# Save individual chains
for chain in 'ABCD':
    print "Saving monomer %s" % chain
    Selection('chain {} and resid 393 to 502'.format(chain), template).atomsel.write(FORMAT_PDB, '{}/{}1.pdb'.format(TMP_DIR, chain))
    Selection('chain {} and resid 508 to 719'.format(chain), template).atomsel.write(FORMAT_PDB, '{}/{}2.pdb'.format(TMP_DIR, chain))

# Load psfgen and topology
VMD.evaltcl("package require psfgen")
VMD.evaltcl("topology %s" % TOPOLOGY)
# Aliasing
VMD.evaltcl("pdbalias residue HIS HSE")
VMD.evaltcl("pdbalias atom ILE CD1 CD")
# Alias terminal oxygen for nitrogen from CT3 patch
VMD.evaltcl("pdbalias atom ALA OXT NT")
def main():

    # Read name of input and output files from command line
    if len(sys.argv)!= 6:
        print("Wrong number of arguments.")
        print("Usage: " + sys.argv[0]  + " <input file of simulation parameters>" + " <input file of particle details>" + " <output vmd file>" + " <orbital outputfile>" + "<energy output file>")
        quit()
    else:
        
        parameter_file = sys.argv[1]
        particle_file = sys.argv[2]
        outfile_name = sys.argv[3]
        orb_file = sys.argv[4]
        energy_file = sys.argv[5]

    # create bodies
    # the input file has all positions in metres and velocities in ms^-1

    system = Particle3D.create_particle(particle_file)
    
    # centre of mass correction for the bodies

    com_correction(system)

    # begginings of position and distance lists for calculating orbitals and apsis

    positions = []
    distances = []

    for s in system:
        positions.append((s.label,[]))
        distances.append((s.label,[]))

    add_to_pos_lists(system,distances,positions)

    # read in simulation parameters from parameter file

    parameters = open(parameter_file, "r")
    lines = parameters.readlines()
    parameters.close()

    params = []

    for l in lines:
        l = l.strip()
        param, value = l.split(":")
        params.append((param,value))

    dt = list(map(lambda x: int(x[1]),(filter(lambda x: "dt" == x[0], params))))[0] # timestep in seconds
    n = list(map(lambda x: int(x[1]),(filter(lambda x: "n" == x[0], params))))[0] # for every n timesteps we will write to vmd, calculate energies etc (no unit)
    num_steps = list(map(lambda x: int(x[1]),(filter(lambda x: "num_steps" == x[0], params))))[0] # number of timesteps (no unit)

    # open vmd file to write to and initialise that it is on its first point

    vmd_file = open(outfile_name , "w")
    point = 1

    # initialise time

    time = 0

    # get initial forces 

    forces = calc.Find_all_forces(system)

    # get inital energies
    
    energies = calc.Calculate_total_energy(system)
    tot_energy = energies[0]
    kin_energy = energies[1]
    pot_energy = energies[2]

    # append energies and time to corresponding lists

    time_list = [time]
    tot_energy_list = [tot_energy]
    kin_energy_list = [kin_energy]
    pot_energy_list = [pot_energy]

    # start the time integration loop

    for i in range(num_steps):

        # update particle position
        calc.Update_position(system,forces, dt)

        # update forces
        new_forces = calc.Find_all_forces(system)

        # update particle velocities by averaging current and new forces
        
        average_forces = []
        
        for i in range(0,len(forces)):
            average_force = (forces[i] + new_forces[i])/2
            average_forces.append(average_force)

        calc.Update_velocity(system,average_forces, dt)

        # re define force
        forces = new_forces

        # increse time
        time += dt

        # every n timesteps

        if time % n == 0:

            VMD.Write_vmd(system,point,vmd_file) # write to vmd file
            point += 1 # update point
            
            # get energies

            energies = calc.Calculate_total_energy(system)
            tot_energy = energies[0]
            kin_energy = energies[1]
            pot_energy = energies[2]
            
            #update energy and time lists

            tot_energy_list.append(tot_energy)
            kin_energy_list.append(kin_energy)
            pot_energy_list.append(pot_energy)
            time_list.append(time)
            
            # append to position and distance lists

            add_to_pos_lists(system,distances,positions)

    # close vmd file
    
    vmd_file.close()

    # open orbital output file and write to it the apsides and orbital periods

    orb_file = open(orb_file , "w")

    for p in positions:
        
        if p[0] == 'Moon': # ensure moon orbits Earth
            
            orbitting = 0
            
            for i in positions:
                if i[0] == 'Earth':
                    orbitting = i

            # check at least one orbit has occured and if not suggests larger number steps

            test = orbit(p[1],orbitting[1],time_list)

            if isinstance(test, str):
                orb_file.write("For " + str(p[0]) + " try a larger number of steps to allow completion of at least one orbit. \n")

            # otherwise prints relevant inormation to orbital file

            else: 
                orb_file.write("The orbit of the " + str(p[0]) + " is: ")
                orb_file.write(str(orbit(p[1],orbitting[1],time_list)) + " days, \n")
                orb_file.write("and the apo- and periapses are (respectively): ")
                orb_file.write(str(Apsides(distances[positions.index(p)][1]))+ " metres. \n")

        elif p[0] == 'Sun': # ignores sun 
            pass
        
        else: # makes all other calculations on assumption of orbitting sun
            for i in positions:
                if i[0] == 'Sun':
                    orbitting = i

            # check at least one orbit has occured and if not suggest larger number steps

            test = orbit(p[1],orbitting[1],time_list)

            if isinstance(test, str): 
                orb_file.write("For " + str(p[0]) + " try a larger number of steps to allow completion of at least one orbit. \n")

            # otherwise prints relevant inormation to orbital file

            else: 
                orb_file.write("The orbit of " + str(p[0]) + " is: ")
                orb_file.write(str(orbit(p[1],orbitting[1],time_list)) + " days, \n")
                orb_file.write("and the apo- and periapses are (respectively): ")
                orb_file.write(str(Apsides(distances[positions.index(p)][1]))+ " metres. \n")
            
    # close orbital output file

    orb_file.close()

    energy_file = open(energy_file , "w")

    energy_file.write("The total energies, kinetic energies, potential energies (in Joules) are as follows: \n")
    for i in range(len(tot_energy_list)):
        energy_file.write(str(tot_energy_list[i]) + "," + str(kin_energy_list[i]) + "," + str(pot_energy_list[i]) + "\n")

    # close energy file

    energy_file.close()
    

    # plotting total energy, kinetic energy and potential energy of the system against time

    pyplot.title('Energy Fluctuation Solar System Total Energy vs Time')
    pyplot.xlabel('Time,s')
    pyplot.ylabel('Total Energy, J')
    pyplot.plot(time_list, tot_energy_list)
    pyplot.show()

    pyplot.title('Energy Fluctuation Solar System Kinetic Energy vs Time')
    pyplot.xlabel('Time,s')
    pyplot.ylabel('Kinetic Energy, J')
    pyplot.plot(time_list, kin_energy_list)
    pyplot.show()

    pyplot.title('Energy Fluctuation Solar System Potential Energy vs Time')
    pyplot.xlabel('Time,s')
    pyplot.ylabel('Potential Energy, J')
    pyplot.plot(time_list, pot_energy_list)
    pyplot.show()
Exemplo n.º 8
0
home = os.environ["HOME"]

# structure files
cbz_gOpt = "{}/Research/FORCE_FIELDS/AMBER/Molecules/CBZ_gaff2/1.resp_charges/2-geomOpt/CBZ_gau_Opt_log.xyz".format(
    home)
#cbz_gaff2_lmpdat = "{}/Research/FORCE_FIELDS/AMBER/Molecules/CBZ_gaff2/4.2.test_MDs/Iteration_3-2/Iteration-3-2_best.lmpdat".format(home)
#cbz_gaff2_dcd    = "{}/Research/FORCE_FIELDS/AMBER/Molecules/CBZ_gaff2/4.2.test_MDs/Iteration_3-2/Iteration-3-2_best_in_vacuo.dcd".format(home)
#cbz_gaff_lmpdat  = "{}/Research/FORCE_FIELDS/AMBER/Molecules/CBZ_gaff2/4.2.test_MDs/Standard_gaff/CBZ.lmpdat".format(home)
#cbz_gaff_dcd     = "{}/Research/FORCE_FIELDS/AMBER/Molecules/CBZ_gaff2/4.2.test_MDs/Standard_gaff/Standard_gaff_in_vacuo.dcd".format(home)
cbz_gaff2_lmpdat = "{}/Research/PAPERS/2017_12/CBZ_FF-evaluation/results/average_structures/cbz_gaff2_average.lmpdat".format(
    home)
cbz_gaff_lmpdat = "{}/Research/PAPERS/2017_12/CBZ_FF-evaluation/results/average_structures/cbz_gaff_average.lmpdat".format(
    home)

# change the scene
VMD.evaltcl("display shadows off")
color_display = color.get_colormap("Display")
color_display["Background"] = "white"
color.set_colormap("Display", color_display)
display.set(depthcue=0)

# load mol and change its representation
# geometry optimized cbz
licor_style = "Licorice 0.1 50 50"
sel_no_h = "not element H"

if molecule.exists(0) != 1:
    molecule.load("xyz", cbz_gOpt)
    molrep.modrep(0,
                  0,
                  sel=sel_no_h,
Exemplo n.º 9
0
        # quenching
        QUENCH_DCD = QUENCH_DCD_RAW.format(MAINDIR, CURCYCLE)
        molecule.read(CURCYCLE, "dcd", QUENCH_DCD, beg=0, end=-1, waitfor=-1)

        # annealing - heating up
        EQUIL_ANNEAL_DCD = EQUIL_ANNEAL_DCD_RAW.format(MAINDIR, CURCYCLE)
        molecule.read(CURCYCLE,
                      "dcd",
                      EQUIL_ANNEAL_DCD,
                      beg=0,
                      end=-1,
                      waitfor=-1)

        # annealing - productive
        ANNEAL_DIR = "{}/anneal_{}".format(MAINDIR, CURCYCLE)
        PROD_ANNEAL_DCDS = get_files(
            "{0}/anneal_{1}/".format(ANNEAL_DIR, CURCYCLE),
            PROD_ANNEAL_DCD_RAW.format(CURCYCLE))

        for CUR_DCD in PROD_ANNEAL_DCDS:
            print(CUR_DCD)
            molecule.read(CURCYCLE, "dcd", CUR_DCD, beg=0, end=-1, waitfor=-1)

        pdb.set_trace()

        # requenching
        REQUENCH_DCD = REQUENCH_DCD_RAW.format(MAINDIR, CURCYCLE)
        molecule.read(CURCYCLE, "dcd", REQUENCH_DCD, beg=0, end=-1, waitfor=-1)
        VMD.evaltcl("mol off {}".format(CURCYCLE))
Exemplo n.º 10
0
# Warning: this is Python 2.5

from Tkinter import *


# A minimal plugin class that just creates an empty window
class MyPlugin:
    def __init__(self):
        self.root = Tk()
        self.root.title("My Plugin Window")


# Function to start the plugin.  Must return the window handle.
def startMyPlugin():
    return MyPlugin().root


if __name__ == "__main__":
    import VMD
    # Register the plugin so that it's not actually created until the
    # first request to open the window.
    VMD.registerExtensionMenu("myplugin", startMyPlugin)

    # Create the plugin now and add it to the Extensions menu.
    # VMD.addExtensionMenu("myplugin", MyPlugin().root)
		return self.rotation.x(), self.rotation.y(), self.rotation.z(), self.rotation.w()

def assign(item, frame):
	item['Rotation']['x'] = frame.get_vec()[0]
	item['Rotation']['y'] = frame.get_vec()[1]
	item['Rotation']['z'] = frame.get_vec()[2]
	item['Rotation']['w'] = frame.get_vec()[3]
	item['BoneName_byte'] = frame.name

def addOneMore(r):
	buff = r.bone_record[0]
	buff = copy.deepcopy(buff)
	r.bone_record.append(buff)
	return buff 

r = VMD.VMDReader('sample_reference.vmd')
r.bone_record = r.bone_record[:1]

joints = [[8,9],[9,10], [8,14],[14,15],[15,16], [8,11],[11,12],[12,13], [8,7],[7,0], [4,5],[5,6],[0,4], [0,1],[1,2],[2,3]]

time = 0
for i in range(586):
	time += 1
	pts = np.float32(sio.loadmat('./pred3d/%08d.mat'%i)['pts'])
	print(pts.shape)
	buf = []
	for i in range(17):
		buf.append(QVector3D(pts[i][0], -pts[i][1], pts[i][2]))
	pts = buf 

	# lowerbody 
Exemplo n.º 12
0
# generate VMD scripts
import sys
sys.path.append('../../src/vmd/')

from getSettings import getSettings
from VMD import *

if __name__ == '__main__':

    # ---- input settings ---- #
    celltype, chrom_lst = getSettings(sys.argv[1:])

    Vmd = VMD()
    for chrId in chrom_lst:

        # ---- generate individual pdb/psf files ---- #
        Vmd.genPdb(celltype, chrId)
        Vmd.genPsf(celltype, chrId)

        # ---- generate individual VMD scripts ---- #
        Vmd.genVMDScript(celltype, chrId)
    print