Пример #1
0
 def run_read_output_surf(self):
     """
     Write the output file according to the template measurements
     """
     tcl_name = output_folder + "/surface_output_" + str(
         self.input_pdb_path).split("/")[-1][0:-4] + "_" + str(
             self.current_chain) + ".tcl"
     run_command = "play " + tcl_name
     evaltcl(run_command)
def check_lammps(filename):

    evaltcl("package require topotools 1.6")
    evaltcl("topo readlammpsdata %s" % filename)

    assert len(set(atomsel("same fragment as protein").resid)) == 284
    assert len(set(atomsel("resname ACE NMA NME").resid)) == 4
    assert len(atomsel("water")) == 32106
    assert len(atomsel("same fragment as lipid")) == 12194

    # Check for the corrrect number of alprenolols
    assert len(atomsel("resname ALP")) == 420
    assert len(set(atomsel("resname ALP").resid)) == 10
    assert "OG301" in set(atomsel("resname ALP").name)
    assert "O1" not in set(atomsel("resname ALP").name)

    # Check coordinates are unique (not zero)
    assert len(atomsel("resname ALP")) == 420
    assert 0.0 not in atomsel("resname ALP").x
Пример #3
0
def test_evaltcl(file_rho):
    from vmd import evaltcl, atomsel, molecule

    molid = int(evaltcl("mol new"))
    assert molecule.get_top() == molid
    assert evaltcl("mol addfile %s type mae waitfor all" % file_rho)
    assert "molecule%d" % molid in evaltcl("mol list")

    with pytest.raises(ValueError):
        evaltcl("atomsel all")

    assert evaltcl("set all_atoms [atomselect %s \" all \" frame %s]" %
                   (molid, 0)) == "atomselect0"
    assert set(evaltcl("$all_atoms get chain").split()) == \
           set(atomsel("all").chain)
    assert set(evaltcl("$all_atoms get name").split()) == \
           set(atomsel("all").name)

    with pytest.raises(ValueError):
        evaltcl("$all_atoms get invalid")
Пример #4
0
    def load_data(self, load_data, align=True):
        """Method for loading trajectory data

        Parameters
        ----------
        load_data : dict
           dictionary of VMD read routine options. See
           VMDMolecule.__init__() docs.
        """

        if not isinstance(load_data, dict):
            raise ValueError("load_data must be a dictionary with "
                             "key-value pairs corresponding to VMD "
                             "read command options.")
        else:
            mol.read(self.molid, **load_data)
            if align:
                self.self_align()
            print("{} frames loaded.".format(mol.numframes(self.molid)))
            evaltcl("display resetview")
Пример #5
0
def test_evaltcl(file_rho):
    from vmd import evaltcl, atomsel, molecule

    molid = int(evaltcl("mol new"))
    assert molecule.get_top() == molid
    assert evaltcl("mol addfile %s type mae waitfor all" % file_rho)
    assert "molecule%d" % molid in evaltcl("mol list")

    with pytest.raises(ValueError):
        evaltcl("atomsel all")

    assert evaltcl("set all_atoms [atomselect %s \" all \" frame %s]"
                   % (molid, 0))  == "atomselect0"
    assert set(evaltcl("$all_atoms get chain").split()) == \
           set(atomsel("all").chain)
    assert set(evaltcl("$all_atoms get name").split()) == \
           set(atomsel("all").name)

    with pytest.raises(ValueError):
        evaltcl("$all_atoms get invalid")
Пример #6
0
    def _psf_to_gromacs(self):

        # Save the .gro coordinate file with VMD
        mid = molecule.load("psf", self.outprefix + ".psf", "pdb",
                            self.outprefix + ".pdb")
        atomsel("all", mid).write("gro", self.outprefix + ".gro")
        molecule.delete(mid)

        # Write a temporary file for a topotools tcl script
        f, temp = tempfile.mkstemp(prefix="topo",
                                   suffix=".tcl",
                                   dir=self.tmp_dir,
                                   text=True)
        with os.fdopen(f, 'w') as fh:
            fh.write("package require topotools 1.6\n")
            fh.write("mol load psf %s.psf pdb %s.pdb\n" %
                     (self.outprefix, self.outprefix))
            fh.write("topo writegmxtop %s.top [list %s ]\n" %
                     (self.outprefix, " ".join(self.parameters)))

        # Run the pbctools tcl script
        output = evaltcl("play %s" % temp)
        print(output)
Пример #7
0
 def run_read_output_inter(self):
     """
     Write the output file according to the template measurements
     """
     output_name = "output/interface_output_A"
     evaltcl('play output/get_interface.tcl.tpl')
Пример #8
0
#Load python packages
from vmd import evaltcl
import numpy as np
from molecule import load
from atomsel import atomsel
import molecule
import math

#Load nanotube package in VMD
evaltcl('package require nanotube')

#make a 5nm x 5nm grpahene sheet
NT=evaltcl('graphene -lx 5 -ly 5 -type zigzag -nlayers 1 -b 1 -a 0 -d 0 -i 0')

#Figure out the correct unit cell size and set it so we can get the correct PBC
all=atomsel()
CCdist=1.42
X=all.get('x')
Y=all.get('y')
pbc_x = np.max(X) - np.min(X) + CCdist
pbc_y = np.max(Y) - np.min(Y) + CCdist * np.sin(60./360.*math.pi*2)
pbc = [ pbc_x, pbc_y, 20 ]

#We need another VMD package to set the periodic boundary conditions / unit cell
evaltcl('package require pbctools')

#We need to use the VMD packag pbctools, which doesn't have a python interface,
#so we explicitly do this by hand with evaltcl
evaltcl('pbc set {%f %f %f}'%(pbc[0],pbc[1],pbc[2]))

evaltcl('package require topotools')
Пример #9
0
 def call_tcl(self,file_path,proc):
     #en construccion metodo para llamar funciones desde tcl
     vmd.evaltcl(run)
     return vmd.evaltcl("mycenter")
Пример #10
0
    def write(self, psf_name):
        """
        Writes the pdb/psf file.

        Args:
          psf_name (str): Prefix for the pdb/psf output files, extension
            will be appended

        Returns:
          topologies (list of str): Topology files that were used in creating
              the psf
        """
        # Clean up all temp files from previous runs if present
        # An earlier check will exit if it's not okay to overwrite here
        self.psf_name = psf_name
        try:
            os.remove('%s.pdb'% self.psf_name)
            os.remove('%s.psf'% self.psf_name)
        except OSError:
            pass

        #  Finds the psfgen package and sets the output file name
        string = '''
        set dir [file join $env(VMDDIR) plugins [vmdinfo arch] tcl psfgen1.6]
        package ifneeded psfgen 1.6 [list load [file join $dir libpsfgen.so]]
        package require psfgen
        set output "%s"
        resetpsf
        ''' % self.psf_name
        self.file.write(string)

        # Put our molecule on top
        old_top = molecule.get_top()
        molecule.set_top(self.molid)

        # Print out topology files
        self.file.write('\n')
        print("Using the following topologies:")
        for top in self.topologies:
            print("  - %s" % top.split("/")[-1])
            self.file.write('   topology %s\n' % top)

        # Mark all atoms as unsaved with the user field
        atomsel('all', molid=self.molid).set('user', 1.0)
        check_atom_names(molid=self.molid)

        # Now ions if present, changing the atom names
        if len(atomsel('element Na Cl K', molid=self.molid)) > 0:
            self._write_ion_blocks()

        # Save water 10k molecules at a time
        if len(atomsel('water', molid=self.molid)):
            self._write_water_blocks()

        # Now lipid
        if len(atomsel(self.lipid_sel)):
            self._write_lipid_blocks()

        if not len(atomsel("resname %s" % _acids, molid=self.molid)):
            print("\tDidn't find any protein.\n")

        # Now handle the protein
        # Save and reload the protein so residue looping is correct
        prot_molid = self._renumber_protein_chains(molid=self.molid)
        extpatches = set()
        for frag in sorted(set(atomsel("resname %s" % _acids,
                                molid=prot_molid).get('fragment'))):
            extpatches.update(self._write_protein_blocks(prot_molid, frag))
        atomsel("same fragment as resname %s" % _acids,
                molid=self.molid).set("user", 0.0)

        # List all patches applied to the protein
        print("Applying the following patches:\n")
        print("\t%s" % "\t".join(extpatches))
        self.file.write(''.join(extpatches))
        self.file.write("\n")

        # Regenerate angles and dihedrals after applying patches
        # Angles must be regenerated FIRST!
        # See http://www.ks.uiuc.edu/Research/namd/mailing_list/namd-l.2009-2010/4137.html
        self.file.write("regenerate angles\nregenerate dihedrals\n")

        # Check if there is anything else and let the user know about it
        leftovers = atomsel('user 1.0', molid=self.molid)
        for lig in set(leftovers.get('resname')):
            residues = self._find_single_residue_names(resname=lig, molid=self.molid)
            self._write_generic_block(residues)

        # Write the output files and run
        string = '''
        writepsf x-plor cmap ${output}.psf
        writepdb ${output}.pdb'''
        self.file.write(string)
        self.file.close()

        evaltcl('play %s' % self.filename)
        self._check_psf_output()

        # Reset top molecule
        molecule.set_top(old_top)

        return self.topologies
Пример #11
0
def run_class_pdb(input_pdb_name):
    """
    Generate the output file and generate the structures with hydrogens
    """
    add_hydrogens(input_pdb_name)
    evaltcl("play add_H.tcl.tpl")
Пример #12
0
    def write(self, psf_name):
        """
        Writes the pdb/psf file.

        Args:
          psf_name (str): Prefix for the pdb/psf output files, extension
            will be appended

        Returns:
          topologies (list of str): Topology files that were used in creating
              the psf
        """
        # Clean up all temp files from previous runs if present
        # An earlier check will exit if it's not okay to overwrite here
        self.psf_name = psf_name
        try:
            os.remove('%s.pdb'% self.psf_name)
            os.remove('%s.psf'% self.psf_name)
        except OSError:
            pass

        #  Finds the psfgen package and sets the output file name
        string = '''
        set dir [file join $env(VMDDIR) plugins [vmdinfo arch] tcl psfgen1.6]
        package ifneeded psfgen 1.6 [list load [file join $dir libpsfgen.so]]
        package require psfgen
        set output "%s"
        resetpsf
        ''' % self.psf_name
        self.file.write(string)

        # Put our molecule on top
        old_top = molecule.get_top()
        molecule.set_top(self.molid)

        # Print out topology files
        self.file.write('\n')
        print("Using the following topologies:")
        for top in self.topologies:
            print("  - %s" % top.split("/")[-1])
            self.file.write('   topology %s\n' % top)

        # Mark all atoms as unsaved with the user field
        atomsel('all', molid=self.molid).set('user', 1.0)
        check_atom_names(molid=self.molid)

        # Now ions if present, changing the atom names
        if len(atomsel('ions', molid=self.molid)) > 0:
            self._write_ion_blocks()

        # Save water 10k molecules at a time
        if len(atomsel('water', molid=self.molid)):
            self._write_water_blocks()

        # Now lipid
        if len(atomsel(self.lipid_sel)):
            self._write_lipid_blocks()

        # Now handle the protein
        # Save and reload the protein so residue looping is correct
        if len(atomsel("resname %s" % _acids, molid=self.molid)):
            extpatches = set()
            for frag in sorted(set(atomsel("resname %s" % _acids,
                                    molid=self.molid).get('fragment'))):
                extpatches.update(self._write_protein_blocks(self.molid, frag))
            atomsel("same fragment as resname %s" % _acids,
                    molid=self.molid).set("user", 0.0)

            # List all patches applied to the protein
            print("Applying the following patches:\n")
            print("\t%s" % "\t".join(extpatches))
            self.file.write(''.join(extpatches))
            self.file.write("\n")
        else:
            print("\tDidn't find any protein. Continuing...\n")

        # Regenerate angles and dihedrals after applying patches
        # Angles must be regenerated FIRST!
        # See http://www.ks.uiuc.edu/Research/namd/mailing_list/namd-l.2009-2010/4137.html
        self.file.write("regenerate angles\nregenerate dihedrals\n")

        # Check if there is anything else and let the user know about it
        leftovers = atomsel('user 1.0', molid=self.molid)
        for lig in set(leftovers.get('resname')):
            residues = self._find_single_residue_names(resname=lig, molid=self.molid)
            self._write_generic_block(residues)

        # Write the output files and run
        string = '''
        writepsf x-plor cmap ${output}.psf
        writepdb ${output}.pdb'''
        self.file.write(string)
        self.file.close()

        evaltcl('play %s' % self.filename)
        self._check_psf_output()

        # Reset top molecule
        molecule.set_top(old_top)

        return self.topologies