Exemple #1
0
def test_pdb_amber_custom_residues(tmpdir):
    from dabble.param import AmberWriter

    p = str(tmpdir)
    molid = molecule.load("pdb", os.path.join(dir, "prepped.pdb"))
    w = AmberWriter(molid,
                    tmp_dir=p,
                    forcefield="amber",
                    hmr=False,
                    extra_topos=[
                        os.path.join(dir, "glx.off"),
                        os.path.join(dir, "lyx.off")
                    ],
                    extra_params=[
                        os.path.join(dir, "join.frcmod"),
                        os.path.join(dir, "analogies.frcmod")
                    ],
                    override_defaults=False)
    w.write(os.path.join(p, "test"))

    # Check for correctness
    m2 = molecule.load("parm7", os.path.join(p, "test.prmtop"), "rst7",
                       os.path.join(p, "test.inpcrd"))
    verify_amber(m2)
    molecule.delete(m2)
Exemple #2
0
def test_amber_params(tmpdir):
    """
    Tests writing a ligand with amber parameters
    """
    from dabble.param import AmberWriter

    # Parameterize with amber parameters
    p = str(tmpdir)
    molid = molecule.load("mae", os.path.join(dir, "07HT2B_WT.mae"))
    w = AmberWriter(molid, tmp_dir=p, forcefield="amber", hmr=False,
                    extra_topos=[os.path.join(dir,"lsd.lib")],
                    extra_params=[os.path.join(dir, "lsd.frcmod")],
                    override_defaults=False)
    w.write(os.path.join(p, "test"))

    # Check output is correct
    m2 = molecule.load("parm7", os.path.join(p, "test.prmtop"),
                       "rst7", os.path.join(p, "test.inpcrd"))
    molecule.set_top(m2)

    # Check the system is correctly built
    assert len(set(atomsel("protein or resname ACE NMA").resid)) == 298
    assert len(atomsel("water")) == 186
    assert len(atomsel("ion")) == 0

    # Check the LSD and CHL (cholesterol) are present
    assert len(atomsel("resname LSD")) == 50
    assert len(atomsel("resname CHL")) == 74

    # Check the partial charges are set
    # Here the LSD library has partial charges of 0 except +0.6 on the N2
    assert len(set(atomsel("resname LSD").charge)) == 2
    assert abs(atomsel("resname LSD and name N2").charge[0] - 0.6) < 0.01
    assert abs(set(atomsel("resname LSD and not name N2").charge).pop()) < 0.01
Exemple #3
0
def test_amber_custom_residues(tmpdir):
    from dabble.param import AmberWriter

    # Generate the file
    p = str(tmpdir)
    molid = molecule.load("mae", os.path.join(dir, "prepped.mae"))
    w = AmberWriter(molid,
                    tmp_dir=p,
                    forcefield="amber",
                    hmr=False,
                    extra_topos=[
                        os.path.join(dir, "glx.off"),
                        os.path.join(dir, "lyx.off")
                    ],
                    extra_params=[
                        os.path.join(dir, "join.frcmod"),
                        os.path.join(dir, "analogies.frcmod")
                    ],
                    override_defaults=False)
    w.write(os.path.join(p, "test"))

    # Load the output file and start checking it
    m2 = molecule.load("parm7", os.path.join(p, "test.prmtop"), "rst7",
                       os.path.join(p, "test.inpcrd"))

    verify_amber(m2)
    molecule.delete(m2)
Exemple #4
0
    def write(self, filename):
        """
        Writes the parameter and topology files.

        Args:
            filename (str): File name to write. Gromacs suffix will be added.
        """
        self.outprefix = filename

        # Charmm forcefield
        if "charmm" in self.forcefield or "opls" in self.forcefield:
            psfgen = CharmmWriter(molid=self.molid,
                                  tmp_dir=self.tmp_dir,
                                  lipid_sel=self.lipid_sel,
                                  forcefield=self.forcefield,
                                  water_model=self.water_model,
                                  hmr=self.hmr,
                                  extra_topos=self.extra_topos,
                                  extra_params=self.extra_params,
                                  override_defaults=self.override)
            print("Writing intermediate psf")
            psfgen.write(self.outprefix)
            self._psf_to_gromacs()

        elif "amber" in self.forcefield:
            prmgen = AmberWriter(molid=self.molid,
                                 tmp_dir=self.tmp_dir,
                                 forcefield=self.forcefield,
                                 water_model=self.water_model,
                                 hmr=self.hmr,
                                 lipid_sel=self.lipid_sel,
                                 extra_topos=self.extra_topos,
                                 extra_params=self.extra_params,
                                 override_defaults=self.override)
            print("Writing intermediate prmtop")
            prmgen.write(self.outprefix)
            self._amber_to_gromacs()

        # Now native GROMACS style for gromos or opls
        else:
            # Currently unsupported
            raise DabbleError("Forcefield '%s' not supported for gromacs" %
                              self.forcefield)

            print("Using the following topology files and/or directories:")
            for top in self.topologies:
                print("  - %s" % os.path.split(top)[1])

            self._set_atom_names()
            self._run_pdb2gmx()
Exemple #5
0
def test_hmr_param(tmpdir):
    """
    Tests phosphorylations on Ser
    Also checks HMR
    """
    from dabble.param import AmberWriter
    from vmd import molecule

    # Build the system with HMR
    p = str(tmpdir)
    molid = molecule.load("mae", os.path.join(dir, "rho_test.mae"))
    w = AmberWriter(tmp_dir=p, molid=molid, hmr=True, forcefield="charmm")
    w.write(os.path.join(p, "test"))
    check_built_system(p)
Exemple #6
0
    def get_parameters(cls, forcefield, water_model):

        if forcefield == "charmm":
            prms = [
                "par_all36m_prot.prm", "par_all36_cgenff.prm",
                "par_all36_lipid.prm", "par_all36_carb.prm",
                "par_all36_na.prm", "toppar_all36_prot_na_combined.str"
            ]
            if water_model == "tip3":
                prms.append("toppar_water_ions.str")
            elif water_model == "tip4e":
                prms.append("toppar_water_ions_tip4p_ew.str")
            elif water_model == "spce":
                prms.append("toppar_water_ions_spc_e.str")

        elif forcefield == "amber":
            from dabble.param import AmberWriter  # avoid circular dependency
            return AmberWriter.get_parameters(forcefield, water_model)

        elif forcefield == "opls":
            prms = ["opls_aam.prm"]
            if water_model != "tip3":
                raise DabbleError("Only TIP3 water model supported for OPLS")

        else:
            raise ValueError("Invalid forcefield: '%s'" % forcefield)

        return [cls._get_forcefield_path(par) for par in prms]
Exemple #7
0
    def get_topologies(cls, forcefield, water_model):

        if forcefield == "charmm":
            topos = [
                "top_all36_caps.rtf", "top_all36_cgenff.rtf",
                "top_all36_prot.rtf", "top_all36_lipid.rtf",
                "top_all36_carb.rtf", "top_all36_na.rtf",
                "toppar_all36_prot_na_combined.str",
                "toppar_all36_prot_fluoro_alkanes.str"
            ]
            if water_model == "tip3":
                topos.append("toppar_water_ions.str")
            elif water_model == "tip4e":
                topos.append("toppar_water_ions_tip4p_ew.str")
            elif water_model == "spce":
                topos.append("toppar_water_ions_spc_e.str")

        elif forcefield == "opls":
            topos = ["opls_aam.rtf", "opls_aam_caps.rtf"]
            if water_model != "tip3":
                raise DabbleError("Only TIP3 water model supported for OPLS")

        elif forcefield == "amber":
            from dabble.param import AmberWriter  # avoid circular dependency
            return AmberWriter.get_topologies(forcefield, water_model)

        else:
            raise ValueError("Invalid forcefield: '%s'" % forcefield)

        return [cls._get_forcefield_path(top) for top in topos]
Exemple #8
0
def test_hmr_param_amber(tmpdir):
    """
    Tests parameterizing with Amber, using phosphoserines
    """
    from dabble.param import AmberWriter
    from vmd import molecule

    # Build system
    p = str(tmpdir)
    molid = molecule.load("mae", os.path.join(dir, "rho_test.mae"))
    w = AmberWriter(tmp_dir=p, molid=molid, hmr=True, forcefield="amber",
                    extra_topos=[os.path.join(os.environ.get("AMBERHOME"),
                                              "dat", "leap", "cmd",
                                              "leaprc.phosaa10")])
    w.write(os.path.join(p, "test"))
    check_built_system(p)
Exemple #9
0
def test_relaxin_disulfides_amber(tmpdir):
    """
    Tests these disulfides with amber
    """
    from dabble.param import AmberWriter
    from vmd import molecule

    # Build the system
    p = str(tmpdir)
    molid = molecule.load("mae", os.path.join(dir, "2MV1_dowserwat.mae"))
    w = AmberWriter(molid=molid, tmp_dir=p, forcefield="amber")
    w.write(os.path.join(p, "test"))

    # Load and sanity check the built system
    m2 = molecule.load("parm7", os.path.join(p, "test.prmtop"))
    check_correctness(m2)
Exemple #10
0
    def get_topologies(cls, forcefield, water_model):
        """
        Gets the path to GROMACS-format topologies for a given force field
        """

        # Amber, Charmm, and OPLS handled by conversion
        if forcefield == "charmm":
            return CharmmWriter.get_topologies(forcefield, water_model)

        if forcefield == "amber":
            return AmberWriter.get_topologies(forcefield, water_model)

        if forcefield == "opls":
            return CharmmWriter.get_topologies(forcefield, water_model)

        # No forcefields really ship with gromacs right now because
        # I found an error in the OPLS AA/M gromacs implementation and
        # they won't respond to my emails

        # Use GROMACS forcefield for the remaining ones
        #if forcefield == "opls":
        #    ffdir = "oplsaam.ff"

        #elif forcefield == "gromos":
        #    ffdir = "gromos54a7.ff"

        raise DabbleError("Unsupported forcefield %s" % forcefield)
Exemple #11
0
    def write(self, filename):
        """
        Writes the parameter and topology files

        Args:
            filename (str): File name to write. File type suffix will be added.
        """
        self.outprefix = filename

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

        # Amber forcefield done with AmberWriter then conversion
        if "amber" in self.forcefield:
            # Avoid circular import by doing it here
            from dabble.param import AmberWriter
            prmtopgen = AmberWriter(molid=self.molid,
                                    tmp_dir=self.tmp_dir,
                                    forcefield=self.forcefield,
                                    water_model=self.water_model,
                                    hmr=self.hmr,
                                    lipid_sel=self.lipid_sel,
                                    extra_topos=self.extra_topos,
                                    extra_params=self.extra_params,
                                    override_defaults=self.override,
                                    debug_verbose=self.debug)
            prmtopgen.write(self.outprefix)
            self._prmtop_to_charmm()

        # Charmm forcefield
        elif "charmm" in self.forcefield:
            self._run_psfgen()

        # OPLS forcefield. Same as charmm but list separately for readability
        elif "opls" in self.forcefield:
            self._run_psfgen()

        else:
            raise DabbleError("Unsupported forcefield '%s' for CharmmWriter" %
                              self.forcefield)

        # Check output and finish up
        self._check_psf_output()

        # Reset top molecule
        molecule.set_top(old_top)
def test_multiligand_prmtop_opls(tmpdir):
    """
    Checks that multiple ligands work with AMBER w/OPLS params.
    Should rename some atoms in matching
    """
    from dabble.param import AmberWriter
    p = str(tmpdir)

    # Parameterize the system. One atom name will be changed.
    molid = molecule.load("mae", os.path.join(dir, "B2AR_10ALPs.mae"))
    w = AmberWriter(tmp_dir=p,
                    molid=molid,
                    forcefield="opls",
                    extra_topos=[os.path.join(dir, "dalp_opls.rtf")],
                    extra_params=[os.path.join(dir, "dalp_opls.prm")])
    w.write(os.path.join(p, "test"))

    # Check results
    check_result("psf", p, lipid=False, solvent=False)
    run_minimization(os.path.join(p, "test.prmtop"))
def test_multiligand_prmtop_charmm(tmpdir):
    """
    Checks that multiple ligands work with AMBER w/CHARMM params.
    Should rename some atoms in matching
    """
    from dabble.param import AmberWriter
    p = str(tmpdir)

    # Parameterize the system. One atom name will be changed.
    molid = molecule.load("mae",
                          os.path.join(dir, "test_multiligand_correct.mae"))
    w = AmberWriter(tmp_dir=p,
                    molid=molid,
                    forcefield="charmm",
                    extra_topos=[os.path.join(dir, "alprenolol.rtf")],
                    extra_params=[os.path.join(dir, "alprenolol.prm")])
    w.write(os.path.join(p, "test"))

    # Check results
    check_result("psf", p)
    run_minimization(os.path.join(p, "test.prmtop"))
def test_multiligand_prmtop_amber(tmpdir):
    """
    Checks that multiple ligands work with AMBER.
    Should rename some atoms in matching
    """
    from dabble.param import AmberWriter
    p = str(tmpdir)

    # Parameterize the system. One atom name will be changed.
    molid = molecule.load("mae",
                          os.path.join(dir, "test_multiligand_correct.mae"))
    w = AmberWriter(tmp_dir=p,
                    molid=molid,
                    forcefield="amber",
                    extra_topos=[os.path.join(dir, "alp.off")],
                    extra_params=[os.path.join(dir, "alp.frcmod")])
    w.write(os.path.join(p, "test"))

    # Load the built system and see if it works
    check_result("prmtop", p)
    run_minimization(os.path.join(p, "test.prmtop"))
Exemple #15
0
    def get_parameters(cls, forcefield, water_model):
        """
        Get the path to GROMACS-format parameter files for a given force field
        """

        # Amber and Charmm handled by converstion
        if forcefield == "charmm":
            return CharmmWriter.get_parameters(forcefield, water_model)

        if forcefield == "amber":
            return AmberWriter.get_parameters(forcefield, water_model)

        if forcefield == "opls":
            return CharmmWriter.get_parameters(forcefield, water_model)

        # Gromacs topologies and parameters are the same directories
        return GromacsWriter.get_topologies(forcefield, water_model)
Exemple #16
0
def write_final_system(out_fmt, out_name, molid, **kwargs):
    """
    Writes the final output in whatever format(s) are requested.
    Always writes a mae format file as well

    Args:
      out_name (str): Filename to output to
      out_fmt (str): format to write the output to
      molid (int): VMD molecule_id to write

      tmp_dir (str): Directory to put temporary files in
      extra_topos (list of str): Extra topology files to use
      extra_params (list of str): Extra parameter files to use
      extra_streams (list of str): Extra stream files to use
      lipid_sel (str): Lipid selection
      hmassrepartition (bool): Whether or not to repartition hydrogen
        masses
      forcefield (str): Force field to use, defaults to charmm
      water_model (str): Water model to use, defaults to tip3
      debug_verbose (bool): Extra debug output from tleap

    Returns:
      (str) main final filename written
    """

    # Set defaults for extra keyword options
    # Do this explicitly here
    if kwargs.get('tmp_dir') is None:
        kwargs['tmp_dir'] = os.getcwd()
    if kwargs.get('lipid_sel') is None:
        kwargs['lipid_sel'] = "lipid or resname POPS POPG"
    if kwargs.get('forcefield') is None:
        kwargs['forcefield'] = "charmm"
    if kwargs.get('water_model') is None:
        kwargs['water_model'] = "tip3"
    if kwargs.get('debug_verbose') is None:
        kwargs['debug_verbose'] = False

    # Write a mae file always, removing the prefix from the output file
    mae_name = '.'.join(out_name.rsplit('.')[:-1]) + '.mae'
    write_ct_blocks(molid=molid,
                    sel='beta 1',
                    output_filename=mae_name,
                    tmp_dir=kwargs.get('tmp_dir', os.getcwd()))
    temp_mol = molecule.load('mae', mae_name)

    if out_fmt == "desmond":
        atomsel('all', molid=temp_mol).write("dms", out_name)

    # For pdb, write an AMBER leap compatible pdb, don't trust the VMD
    # pdb writing routine
    elif out_fmt == "pdb":
        atomsel("all", molid=temp_mol).write("pdb", out_name)

    # If we want a parameterized format like amber or charmm, a psf must
    # first be written which does the atom typing, etc
    elif out_fmt == "charmm":
        writer = CharmmWriter(molid=temp_mol,
                              tmp_dir=kwargs['tmp_dir'],
                              forcefield=kwargs['forcefield'],
                              water_model=kwargs['water_model'],
                              lipid_sel=kwargs['lipid_sel'],
                              extra_topos=kwargs.get('extra_topos', []),
                              debug_verbose=kwargs.get('debug_verbose', False))
        writer.write(mae_name.replace(".mae", ""))

    # For amber format files, invoke the parmed chamber routine
    elif out_fmt == "amber":
        print("Writing AMBER format files with %s parameters. "
              "This may take a moment...\n" % kwargs.get("forcefield"))

        writeit = AmberWriter(molid=temp_mol,
                              tmp_dir=kwargs['tmp_dir'],
                              forcefield=kwargs['forcefield'],
                              water_model=kwargs['water_model'],
                              lipid_sel=kwargs.get('lipid_sel'),
                              hmr=kwargs.get('hmassrepartition'),
                              extra_topos=kwargs.get('extra_topos', []),
                              extra_params=kwargs.get('extra_params', []),
                              debug_verbose=kwargs.get('debug_verbose'))
        writeit.write(mae_name.replace(".mae", ""))

    # For gromacs files, use either topotools or parmed depending on
    # forcefield. GromacsWriter handles this for us
    elif out_fmt == "gromacs":
        if "charmm" in kwargs.get('forcefield'):
            print("Writing Gromacs format files with CHARMM parameters. "
                  "This may take a moment...\n")
        else:
            print("Writing Gromacs format files with Amber parameters. "
                  "This may take a moment...\n")

        writeit = GromacsWriter(molid=temp_mol,
                                tmp_dir=kwargs['tmp_dir'],
                                forcefield=kwargs['forcefield'],
                                water_model=kwargs['water_model'])
        writeit.write(mae_name.replace(".mae", ""))

    # LAMMPS has its own writer
    elif out_fmt == "lammps":
        writeit = LammpsWriter(molid=temp_mol, *kwargs)
        writeit.write(mae_name.replace(".mae", ""))

    molecule.delete(temp_mol)
    return out_name
Exemple #17
0
def test_covalent_ligand_amber(tmpdir):
    """
    Tests covalently bound ligand parameterization.
    Also tests for detection of phosphorylations on amino acids.

    Sanity checks differ here from the charmm once since numbering in
    the prmtop file is different.
    """
    from vmd import atomsel, molecule
    from dabble.param import AmberWriter

    # Parameterize with charmm parameters
    p = str(tmpdir)
    molid = molecule.load(
        "mae", os.path.join(dir, "rho_arr_CYP_prepped_aligned_dowsered.mae"))
    w = AmberWriter(tmp_dir=p,
                    molid=molid,
                    lipid_sel="lipid",
                    forcefield="amber",
                    extra_topos=[
                        os.path.join(dir, "cyp.off"),
                        os.path.join(os.environ.get("AMBERHOME"), "dat",
                                     "leap", "cmd", "leaprc.phosaa10")
                    ],
                    extra_params=[
                        os.path.join(dir, "cyp.frcmod"),
                        os.path.join(dir, "analogies.frcmod")
                    ])
    w.write(os.path.join(p, "test"))

    # Load the result
    m2 = molecule.load("parm7", os.path.join(p, "test.prmtop"))
    molecule.set_top(m2)

    # Sanity check the system was built completely
    assert len(set(atomsel("protein or resname ACE NME").resid)) == 699
    assert len(set(atomsel("protein or resname ACE NME").residue)) == 699
    assert len(set(atomsel("resname ACE NME").resid)) == 4
    assert len(atomsel("water")) == 654
    assert len(set(atomsel("all").fragment)) == 220

    # Check for palmitoylation
    assert len(atomsel("resname CYP")) == 116
    assert set(atomsel("resname CYP").resid) == set([323, 324])

    # Check for protonation on Asp83
    # Check for no protonation on Asp334
    assert len(atomsel("resid 84 and resname ASH")) == 13
    assert len(atomsel("resid 332 and resname ASP")) == 12
    assert "OH" in atomsel("resid 84 and resname ASH").type
    assert "OH" not in atomsel("resid 332 and resname ASP").type

    # Check for protonation on Glu134A
    assert len(atomsel("resid 135 and resname GLH")) == 16
    assert len(atomsel("resid 248 and resname GLU")) == 15
    assert "OH" in atomsel("resid 135 and resname GLH").type
    assert "OH" not in atomsel("resid 332 and resname GLU").type

    # Check that Ser98 is normal
    assert len(atomsel("resid 99 and resname SER")) == 11
    assert "P" not in atomsel("resid 99 and resname SER").type
    assert "OH" in atomsel("resid 99 and resname SER").type

    # Check for phosphorylation on Ser334
    assert len(atomsel("resid 335 and resname SEP")) == 14
    assert "P" in atomsel("resid 335 and resname SEP").type
    assert "OH" not in atomsel("resid 335 and resname SEP").type

    # Check for phosphorylation on Ser338
    assert len(atomsel("resid 339 and resname SEP")) == 14
    assert "P" in atomsel("resid 339 and resname SEP").type
    assert "OH" not in atomsel("resid 339 and resname SEP").type

    # Check for disulfide bonds
    assert all(len(x) == 2 for x in atomsel("resname CYX and element S").bonds)