Exemplo n.º 1
0
 def center_simulations(self,atomselect1,new_dcd_path,stride):
     #centra el dcd. similiar a vecinvert pero para trayectoria.
     count=0
     for frame in range(Trajectory.num_frames(self)):
         sel1 = atomsel(selection=atomselect1, molid=self.molID, frame=frame) 
         sel1.moveby(-1*np.array((sel1.center(sel1.mass))))
     molecule.write(self.molID,"dcd",new_dcd_path,stride)
Exemplo n.º 2
0
    def delete_frames(self,atomselect1,cutoff,new_dcd_path,stride):
        #hay que limpiar y depurar bien 12-03-21
        distance_mass_weight=[]
        count=0
        for frame in range(Trajectory.num_frames(self)):
            #protein  = atomsel(selection="protein", molid=molid, frame=frame) 
            sel1 = atomsel(selection=atomselect1, molid=self.molID, frame=frame) 
            #sel2 =atomsel(selection=atomselect2, molid=self.molID, frame=frame)
            
            sel1_x = np.array((sel1.center(sel1.mass)[0]))
            sel2_y= np.array((sel1.center(sel1.mass)[1]))
            if sel1_x < 0:
                print ("borrando "+str(frame))
                count=count+1
                molecule.delframe(self.molID,frame,frame)
                continue
            distance_mass_weight.append(sel1_x)

            #sel1.write('dcd','vsd1000.dcd')
            #
            #
        print ("borrados ",count)    
        molecule.write(self.molID,"dcd",new_dcd_path,stride)
        
            
        return distance_mass_weight
Exemplo n.º 3
0
 def pdbs_from_dcd(self,atomselect1,output):
     vector_radio=[]
     for frame in range(Trajectory.num_frames(self)):
         
         #protein  = atomsel(selection=atomselect1, molid=self.molID, frame=frame) 
         #last_frame = molecule.numframes - 1
         #atomsel.write()
         molecule.write(self.molID, "pdb", "last_frame.pdb", first=frame)
         #vector_radio.append(radio_giro)
Exemplo n.º 4
0
  def save(self, filename, filetype=None, first=0, last=-1, step=1, waitfor=-1, sel=None):
    """
    Save timesteps to the given file.  The filetype will be guessed from
    the filename extension; this can be overridden by setting the filetype
    option.  first, last, and step control which timesteps to save.  Returns
    the number of frames written before the command completes.
    """
    if filetype is None:
      filetype = self._guessFiletype(filename)
####################################################
# XXX AtomSel is no longer imported automatically,
#     so the following piece of code will fail when
#     using the save() method with a selection.
#     if the selection is an atomsel builtin type, it
#     can be passed on directly. otherwise we get a
#     reasonable error message. so this chunk is no
#     longer needed.  AK. 2009/07/21
####################################################
#    if sel:
#      if isinstance(sel, VMD.AtomSel.AtomSel):
#        sel=sel.list()
#      else:
#        try:
#          sel=tuple(sel)
#        except:
#          sel=None
####################################################
    nframes = molecule.write(self.id, filetype, filename, first, last, step, waitfor, selection=sel)
    if nframes < 0:
      raise IOError("Unable to save file: %s" % filename)
    return nframes
Exemplo n.º 5
0
 def the_static_method(vector_pdb,output,outputDCD):
    files=' '.join(map(str,vector_pdb))
    #print (files)
    i=0
    with open('sort_ligand_order.txt', 'w') as filehandle:
        for listitem in vector_pdb:
            #print (listitem)
            nameFile=listitem.split("/")
            filehandle.write('%s' % str(i)+"\t"+nameFile[-1]+"\n")
            i+=1
    
    
    subprocess.call("cat "+files+"> "+ output,shell=True)
    molID=molecule.load2('pdb',output)
    print (molecule.numframes(molID))
    sel1 = atomsel(selection="segname TOX") 
    molecule.write(molID,'dcd',outputDCD,0,-1,1,sel1)
    molecule.cancel
    return output
Exemplo n.º 6
0
thedir = os.path.abspath(
    input("Which directory contains step5_assembly.{psf,crd}? > "))
if not os.path.isdir(thedir):
    raise ValueError("%s not a valid directory" % thedir)

crd = os.path.join(thedir, "step5_assembly.crd")
psf = os.path.join(thedir, "step5_assembly.psf")

if not os.path.isfile(crd):
    raise ValueError("No pdb file in directory!")
if not os.path.isfile(psf):
    raise ValueError("No psf file in directory!")

molid = molecule.load('psf', psf, 'cor', crd)
xs = atomsel().get('x')
ys = atomsel().get('y')
zs = atomsel().get('z')

# 0.5A buffer to make it tile nicer
molecule.set_periodic(molid=molid,
                      a=max(xs) - min(xs) - 8.0,
                      b=max(ys) - min(ys) - 8.0,
                      c=max(zs) - min(zs) - 8.0,
                      alpha=90.,
                      beta=90.,
                      gamma=90.)

outfile = os.path.join(thedir, "step5_assembly_dabble.mae")
molecule.write(molid=molid, filetype='mae', filename=outfile)
Exemplo n.º 7
0
def test_write(tmpdir, file_3frames):

    m = molecule.load("pdb", struct_file=file_3frames)
    tmpdir = str(tmpdir)

    # Deprecated arguments
    with pytest.warns(DeprecationWarning):
        molecule.write(m,
                       "psf",
                       beg=0,
                       end=1,
                       filename=os.path.join(tmpdir, "deprecated.psf"))

    # Write with stride
    molecule.write(molid=m,
                   filetype="pdb",
                   first=0,
                   stride=2,
                   filename=os.path.join(tmpdir, "2frames.pdb"))
    m2 = molecule.load("pdb", os.path.join(tmpdir, "2frames.pdb"))
    assert molecule.numframes(m2) == 2

    # Write a selection
    sel = atomsel("resname ALA", molid=m)
    molecule.write(m,
                   "mae",
                   selection=sel,
                   first=0,
                   last=0,
                   filename=os.path.join(tmpdir, "ala.mae"))
    m3 = molecule.load("mae", os.path.join(tmpdir, "ala.mae"))
    assert molecule.numframes(m3) == 1
    assert set(atomsel(molid=m3).resname) == set(["ALA"])

    # Write an invalid selection on a different molid
    sel2 = atomsel("resname ALA", molid=m3)
    with pytest.raises(ValueError):
        molecule.write(m,
                       "mae",
                       os.path.join(tmpdir, "badsel.mae"),
                       selection=sel2)

    # Write a nonexistent atom selection
    with pytest.raises(TypeError):
        molecule.write(m,
                       "mae",
                       os.path.join(tmpdir, "badsel.mae"),
                       selection=None)

    # Write zero frames
    with pytest.raises(ValueError):
        molecule.write(first=20,
                       last=21,
                       molid=m,
                       filetype="psf",
                       filename=os.path.join(tmpdir, "zeroframes.psf"))

    # Write to an invalid file name (in this case, a directory)
    with pytest.raises(ValueError):
        molecule.write(m, "pdb", filename=os.path.join(tmpdir, "."))

    molecule.delete(m)
    molecule.delete(m2)
    molecule.delete(m3)
Exemplo n.º 8
0
 def get_pdb_trajectory(self,output,first_frame,last_frame):
     
     path_output=output+str(first_frame)+".pdb"
     #protein  = atomsel(selection="protein", molid=molid, frame=frame) 
     molecule.write(self.molID, "pdb",path_output, first=first_frame,last=last_frame)
     return path_output
Exemplo n.º 9
0
def test_write(tmpdir, file_3frames):

    m = molecule.load("pdb", struct_file=file_3frames)
    tmpdir = str(tmpdir)

    # Deprecated arguments
    with pytest.warns(DeprecationWarning):
        molecule.write(m, "psf", beg=0, end=1,
                       filename=os.path.join(tmpdir, "deprecated.psf"))

    # Write with stride
    molecule.write(molid=m, filetype="pdb", first=0, stride=2,
                   filename=os.path.join(tmpdir, "2frames.pdb"))
    m2 = molecule.load("pdb", os.path.join(tmpdir, "2frames.pdb"))
    assert molecule.numframes(m2) == 2

    # Write a selection
    sel = atomsel("resname ALA", molid=m)
    molecule.write(m, "mae", selection=sel, first=0, last=0,
                   filename=os.path.join(tmpdir, "ala.mae"))
    m3 = molecule.load("mae", os.path.join(tmpdir, "ala.mae"))
    assert molecule.numframes(m3) == 1
    assert set(atomsel(molid=m3).resname) == set(["ALA"])

    # Write an invalid selection on a different molid
    sel2 = atomsel("resname ALA", molid=m3)
    with pytest.raises(ValueError):
        molecule.write(m, "mae", os.path.join(tmpdir, "badsel.mae"),
                       selection=sel2)

    # Write a nonexistent atom selection
    with pytest.raises(TypeError):
        molecule.write(m, "mae", os.path.join(tmpdir, "badsel.mae"),
                       selection=None)

    # Write zero frames
    with pytest.raises(ValueError):
        molecule.write(first=20, last=21, molid=m, filetype="psf",
                       filename=os.path.join(tmpdir, "zeroframes.psf"))

    # Write to an invalid file name (in this case, a directory)
    with pytest.raises(ValueError):
        molecule.write(m, "pdb", filename=os.path.join(tmpdir, "."))

    molecule.delete(m)
    molecule.delete(m2)
    molecule.delete(m3)
Exemplo n.º 10
0
import os
from vmd import atomsel, molecule

thedir = os.path.abspath(input("Which directory contains step5_assembly.{psf,crd}? > "))
if not os.path.isdir(thedir):
    raise ValueError("%s not a valid directory" % thedir)

crd = os.path.join(thedir, "step5_assembly.crd")
psf = os.path.join(thedir, "step5_assembly.psf")

if not os.path.isfile(crd):
    raise ValueError("No pdb file in directory!")
if not os.path.isfile(psf):
    raise ValueError("No psf file in directory!")

molid = molecule.load('psf', psf, 'cor', crd)
xs = atomsel().get('x')
ys = atomsel().get('y')
zs = atomsel().get('z')

# 0.5A buffer to make it tile nicer
molecule.set_periodic(molid=molid,
                      a=max(xs)-min(xs)-8.0,
                      b=max(ys)-min(ys)-8.0,
                      c=max(zs)-min(zs)-8.0,
                      alpha=90., beta=90., gamma=90.)

outfile = os.path.join(thedir, "step5_assembly_dabble.mae")
molecule.write(molid=molid, filetype='mae', filename=outfile)