Example #1
0
    def test_mm_options_as_string(self):
        traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))
        igb = 8
        mm_options = sander.gas_input(igb)
        mm_options_str = 'mm_options = sander.gas_input(8)'

        e0 = pt.energy_decomposition(traj, mm_options=mm_options, dtype='dict')
        e1 = pt.energy_decomposition(traj,
                                     mm_options=mm_options_str,
                                     dtype='dict')
        assert sorted(e0) == sorted(e1)
    def test_frame_indices(self):
        traj = pt.iterload('data/tz2.nc', 'data/tz2.parm7')
        frame_indices = [0, 6, 7, 4, 5]

        data_without_frame_indices = pt.energy_decomposition(traj, igb=8)
        data_with_frame_indices = pt.energy_decomposition(
            traj, igb=8, frame_indices=frame_indices)
        data_with_frame_indices_2 = pt.energy_decomposition(
            traj[frame_indices], igb=8)

        for key in data_without_frame_indices:
            aa_eq(data_without_frame_indices[key][frame_indices],
                  data_with_frame_indices[key])
            aa_eq(data_without_frame_indices[key][frame_indices],
                  data_with_frame_indices_2[key])
    def test_GB_QMMM(self):
        # compare to saved test: GB + QMMM
        topfile = os.path.join(amberhome, "test/qmmm2/lysine_PM3_qmgb2/prmtop")
        rstfile = os.path.join(amberhome,
                               "test/qmmm2/lysine_PM3_qmgb2/lysine.crd")
        traj = pt.load(rstfile, topfile)

        options = sander.gas_input(1)
        options.cut = 99.0
        options.ifqnt = 1
        qm_options = sander.qm_input()
        qm_options.iqmatoms[:3] = [8, 9, 10]
        qm_options.qm_theory = "PM3"
        qm_options.qmcharge = 0
        qm_options.qmgb = 2
        qm_options.adjust_q = 0

        edict = pt.energy_decomposition(traj=traj,
                                        mm_options=options,
                                        qm_options=qm_options)
        assert_close(edict['bond'][0], 0.0016, tol=3E-4)
        assert_close(edict['vdw'][0], 0.1908, tol=3E-4)
        assert_close(edict['vdw_14'][0], 3.7051, tol=3E-4)
        assert_close(edict['elec'][0], -4.1241, tol=3E-4)
        assert_close(edict['elec_14'][0], 65.9137, tol=3E-4)
        assert_close(edict['gb'][0], -80.1406, tol=3E-4)
        assert_close(edict['scf'][0], -11.9100, tol=3E-4)
    def test_PME_QMMM(self):
        # compare to saved test: PME + QMMM
        topfile = os.path.join(amberhome,
                               "test/qmmm2/MechEm_nma-spcfwbox/prmtop")
        rstfile = os.path.join(amberhome,
                               "test/qmmm2/MechEm_nma-spcfwbox/inpcrd")
        traj = pt.load(rstfile, topfile)

        options = sander.pme_input()
        options.cut = 8.0
        options.ifqnt = 1
        options.jfastw = 4

        qm_options = sander.QmInputOptions()
        qm_options.qm_theory = "PDDG-PM3"
        qm_options.qmmask = ":1-2"
        qm_options.qmcharge = 0
        qm_options.scfconv = 1e-10
        qmmm_tight_p_conv = 1
        qm_options.qmmm_int = 5

        edict = pt.energy_decomposition(traj=traj,
                                        mm_options=options,
                                        qm_options=qm_options)
        assert_close(edict['bond'][0], 605.7349, tol=3E-4)
        assert_close(edict['vdw_14'][0], 0.0000, tol=3E-4)
        assert_close(edict['elec_14'][0], 0.0000, tol=3E-4)
        assert_close(edict['elec'][0], -7409.7167, tol=3E-1)
        assert_close(edict['scf'][0], -37.1277, tol=3E-4)
    def test_PME_QMMM(self):
        # compare to saved test: PME + QMMM
        topfile = os.path.join(amberhome,
                               "test/qmmm2/MechEm_nma-spcfwbox/prmtop")
        rstfile = os.path.join(amberhome,
                               "test/qmmm2/MechEm_nma-spcfwbox/inpcrd")
        traj = pt.load(rstfile, topfile)

        options = sander.pme_input()
        options.cut = 8.0
        options.ifqnt = 1
        options.jfastw = 4

        qm_options = sander.QmInputOptions()
        qm_options.qm_theory = "PDDG-PM3"
        qm_options.qmmask = ":1-2"
        qm_options.qmcharge = 0
        qm_options.scfconv = 1e-10
        qmmm_tight_p_conv = 1
        qm_options.qmmm_int = 5

        edict = pt.energy_decomposition(traj=traj,
                                        mm_options=options,
                                        qm_options=qm_options)
        assert_close(edict['bond'][0], 605.7349, tol=3E-4)
        assert_close(edict['vdw_14'][0], 0.0000, tol=3E-4)
        assert_close(edict['elec_14'][0], 0.0000, tol=3E-4)
        assert_close(edict['elec'][0], -7409.7167, tol=3E-1)
        assert_close(edict['scf'][0], -37.1277, tol=3E-4)
    def test_GB_QMMM(self):
        # compare to saved test: GB + QMMM
        topfile = os.path.join(amberhome, "test/qmmm2/lysine_PM3_qmgb2/prmtop")
        rstfile = os.path.join(amberhome,
                               "test/qmmm2/lysine_PM3_qmgb2/lysine.crd")
        traj = pt.load(rstfile, topfile)

        options = sander.gas_input(1)
        options.cut = 99.0
        options.ifqnt = 1
        qm_options = sander.qm_input()
        qm_options.iqmatoms[:3] = [8, 9, 10]
        qm_options.qm_theory = "PM3"
        qm_options.qmcharge = 0
        qm_options.qmgb = 2
        qm_options.adjust_q = 0

        edict = pt.energy_decomposition(traj=traj,
                                        mm_options=options,
                                        qm_options=qm_options)
        assert_close(edict['bond'][0], 0.0016, tol=3E-4)
        assert_close(edict['vdw'][0], 0.1908, tol=3E-4)
        assert_close(edict['vdw_14'][0], 3.7051, tol=3E-4)
        assert_close(edict['elec'][0], -4.1241, tol=3E-4)
        assert_close(edict['elec_14'][0], 65.9137, tol=3E-4)
        assert_close(edict['gb'][0], -80.1406, tol=3E-4)
        assert_close(edict['scf'][0], -11.9100, tol=3E-4)
    def test_frame_indices(self):
        traj = pt.iterload('data/tz2.nc', 'data/tz2.parm7')
        frame_indices = [0, 6, 7, 4, 5]

        data_without_frame_indices = pt.energy_decomposition(traj, igb=8)
        data_with_frame_indices = pt.energy_decomposition(
            traj,
            igb=8,
            frame_indices=frame_indices)
        data_with_frame_indices_2 = pt.energy_decomposition(
            traj[frame_indices],
            igb=8)

        for key in data_without_frame_indices:
            aa_eq(data_without_frame_indices[key][frame_indices],
                  data_with_frame_indices[key])
            aa_eq(data_without_frame_indices[key][frame_indices],
                  data_with_frame_indices_2[key])
Example #8
0
 def test_sander_pmap_simple(self):
     traj = pt.iterload(fn('Tc5b.x'), fn('Tc5b.top'))
     fname = traj.top.filename
     serial = pt.energy_decomposition(traj, prmtop=fname)['dihedral']
     parallel = pt.pmap(n_cores=4,
                        func=pt.energy_decomposition,
                        traj=traj,
                        prmtop=fname)['dihedral']
     aa_eq(serial, parallel)
Example #9
0
 def test_sander_pmap_simple(self):
     traj = pt.iterload('./data/Tc5b.x', './data/Tc5b.top')
     fname = traj.top.filename
     serial = pt.energy_decomposition(traj, prmtop=fname)['dihedral']
     parallel = pt.pmap(n_cores=4,
                        func=pt.energy_decomposition,
                        traj=traj,
                        prmtop=fname)['dihedral']
     aa_eq(serial, parallel)
def main():
    folder = sys.argv[1]
    files = glob("{}/min*rst7".format(folder))
    parm = glob("{}/*.parm7".format(folder))[0]

    traj = pt.iterload(files, top=parm)

    energies = pt.energy_decomposition(traj, igb=8)["tot"]
    for fn, potential in zip(files, energies):
        print(fn, potential)
 def test_PME(self):
     # compare to saved test: PME
     topfile = os.path.join(amberhome, "test/4096wat/prmtop")
     rstfile = os.path.join(amberhome, "test/4096wat/eq1.x")
     traj = pt.iterload(rstfile, topfile)
     options = sander.pme_input()
     options.cut = 8.0
     edict = pt.energy_decomposition(traj=traj, mm_options=options)
     assert_close(edict['bond'][0], 0., tol=3E-4)
     assert_close(edict['vdw'][0], 6028.9517, tol=3E-4)
     assert_close(edict['elec'][0], -45371.5995, tol=3E-4)
Example #12
0
    def test_0(self):
        if os.path.exists(amberhome):
            from pytraj.amber_wrapper import minimize

            traj = pt.iterload("./data/Ala3/Ala3.crd", "./data/Ala3/Ala3.top")
            t0 = traj[:1]

            if has_("sander"):
                print('egb: ', pt.energy_decomposition(t0, igb=8)['gb'])

            minimize(t0)

            self.assertRaises(ValueError, lambda: minimize(traj))

            if has_("sander"):
                print('egb: ', pt.energy_decomposition(t0, igb=8)['gb'])

            # load saved file
            saved_coords = pt.load("./data/Ala3/min/min.r", traj.top).xyz
            aa_eq(t0.xyz, saved_coords, decimal=5)
Example #13
0
    def test_0(self):
        if os.path.exists(amberhome):
            from pytraj.amber_wrapper import minimize

            traj = pt.iterload("./data/Ala3/Ala3.crd", "./data/Ala3/Ala3.top")
            t0 = traj[:1]

            if has_("sander"):
                print('egb: ', pt.energy_decomposition(t0, igb=8)['gb'])

            minimize(t0)

            self.assertRaises(ValueError, lambda: minimize(traj))

            if has_("sander"):
                print('egb: ', pt.energy_decomposition(t0, igb=8)['gb'])

            # load saved file
            saved_coords = pt.load("./data/Ala3/min/min.r", traj.top).xyz
            aa_eq(t0.xyz, saved_coords, decimal=5)
 def test_PME(self):
     # compare to saved test: PME
     topfile = os.path.join(amberhome, "test/4096wat/prmtop")
     rstfile = os.path.join(amberhome, "test/4096wat/eq1.x")
     traj = pt.iterload(rstfile, topfile)
     options = sander.pme_input()
     options.cut = 8.0
     edict = pt.energy_decomposition(traj=traj, mm_options=options)
     assert_close(edict['bond'][0], 0., tol=3E-4)
     assert_close(edict['vdw'][0], 6028.9517, tol=3E-4)
     assert_close(edict['elec'][0], -45371.5995, tol=3E-4)
 def test_gbneck2nu(self):
     # compare to saved test: GBneck2nu
     topfile = os.path.join(amberhome, "test/gbneck2nu/1hji/prmtop")
     rstfile = os.path.join(amberhome, "test/gbneck2nu/1hji/min.r")
     traj = pt.load(rstfile, topfile)
     options = sander.gas_input(8)
     options.cut = 9999.0
     edict = pt.energy_decomposition(traj=traj,
                                     mm_options=options,
                                     prmtop=topfile)
     assert_close(edict['gb'][0], -2287.6880, tol=3E-4)
     assert_close(edict['gb'][0], -2287.6880, tol=3E-4)
     assert_close(edict['elec'][0], -1659.5740, tol=3E-4)
     assert_close(edict['vdw'][0], 384.2512, tol=3E-4)
 def test_gbneck2nu(self):
     # compare to saved test: GBneck2nu
     topfile = os.path.join(amberhome, "test/gbneck2nu/1hji/prmtop")
     rstfile = os.path.join(amberhome, "test/gbneck2nu/1hji/min.r")
     traj = pt.load(rstfile, topfile)
     options = sander.gas_input(8)
     options.cut = 9999.0
     edict = pt.energy_decomposition(traj=traj,
                                     mm_options=options,
                                     prmtop=topfile)
     assert_close(edict['gb'][0], -2287.6880, tol=3E-4)
     assert_close(edict['gb'][0], -2287.6880, tol=3E-4)
     assert_close(edict['elec'][0], -1659.5740, tol=3E-4)
     assert_close(edict['vdw'][0], 384.2512, tol=3E-4)
    def test_GB(self):
        # compare to saved test: GB
        topfile = os.path.join(amberhome, "test/gb7_trx/prmtop_an")
        rstfile = os.path.join(amberhome, "test/gb7_trx/trxox.2.4ns.x")
        traj = pt.load(rstfile, topfile)
        options = sander.gas_input(7)
        options.cut = 9999.0
        options.saltcon = 0.2
        options.gbsa = 1
        edict = pt.energy_decomposition(traj=traj,
                                        mm_options=options,
                                        prmtop=topfile)
        assert_close(edict['bond'][0], 631.8993, tol=3E-4)
        assert_close(edict['angle'][0], 898.2543, tol=3E-4)
        assert_close(edict['surf'][0], 33.8338, tol=3E-4)
        assert_close(edict['gb'][0], -1943.0838, tol=3E-4)

        # dummy test to make sure `energy_decomposition` can work with list
        edict2 = pt.energy_decomposition(traj=[
            traj,
        ],
                                         mm_options=options,
                                         prmtop=topfile,
                                         top=traj.top)
        edict3 = pt.energy_decomposition(traj=traj(),
                                         mm_options=options,
                                         prmtop=topfile,
                                         top=traj.top)
        edict4 = pt.energy_decomposition(traj=[traj[:5], traj[5:]],
                                         mm_options=options,
                                         prmtop=topfile,
                                         top=traj.top)
        edict5 = pt.energy_decomposition(traj=[traj[:5],
                                               traj(start=5)],
                                         mm_options=options,
                                         prmtop=topfile,
                                         top=traj.top)
        # test dtype
        dslist = pt.energy_decomposition(traj=[
            traj,
        ],
                                         mm_options=options,
                                         prmtop=topfile,
                                         top=traj.top,
                                         dtype='dataset')
        assert edict == edict2
        assert edict == edict3
        assert edict == edict4
        assert sorted(dslist.to_dict()) == sorted(edict)
Example #18
0
    def test_sander_pmap_with_options(self):
        '''need to write mm_options as text
        '''
        code_local = '''
        mm_options = sander.gas_input(8)
        '''

        traj = pt.iterload(fn('Tc5b.x'), fn('Tc5b.top'))

        for code in [code_global, code_local]:
            data_parallel = pt.pmap(pt.energy_decomposition,
                                    traj,
                                    mm_options=code,
                                    n_cores=3,
                                    dtype='dict')

            mm_options = sander.gas_input(8)
            data_serial = pt.energy_decomposition(traj,
                                                  mm_options=mm_options,
                                                  dtype='dict')
            aa_eq(pt.tools.dict_to_ndarray(data_parallel),
                  pt.tools.dict_to_ndarray(data_serial))
Example #19
0
    def test_sander_pmap_with_options(self):
        '''need to write mm_options as text
        '''
        code_local = '''
        mm_options = sander.gas_input(8)
        '''

        traj = pt.iterload('./data/Tc5b.x', './data/Tc5b.top')

        for code in [code_global, code_local]:
            data_parallel = pt.pmap(pt.energy_decomposition,
                                    traj,
                                    mm_options=code,
                                    n_cores=3,
                                    dtype='dict')

            mm_options = sander.gas_input(8)
            data_serial = pt.energy_decomposition(traj,
                                                  mm_options=mm_options,
                                                  dtype='dict')
            aa_eq(
                pt.tools.dict_to_ndarray(data_parallel),
                pt.tools.dict_to_ndarray(data_serial))
    def test_GB(self):
        # compare to saved test: GB
        topfile = os.path.join(amberhome, "test/gb7_trx/prmtop_an")
        rstfile = os.path.join(amberhome, "test/gb7_trx/trxox.2.4ns.x")
        traj = pt.load(rstfile, topfile)
        options = sander.gas_input(7)
        options.cut = 9999.0
        options.saltcon = 0.2
        options.gbsa = 1
        edict = pt.energy_decomposition(traj=traj,
                                        mm_options=options,
                                        prmtop=topfile)
        assert_close(edict['bond'][0], 631.8993, tol=3E-4)
        assert_close(edict['angle'][0], 898.2543, tol=3E-4)
        assert_close(edict['surf'][0], 33.8338, tol=3E-4)
        assert_close(edict['gb'][0], -1943.0838, tol=3E-4)

        # dummy test to make sure `energy_decomposition` can work with list
        edict2 = pt.energy_decomposition(traj=[traj, ],
                                         mm_options=options,
                                         prmtop=topfile,
                                         top=traj.top)
        edict3 = pt.energy_decomposition(traj=traj(),
                                         mm_options=options,
                                         prmtop=topfile,
                                         top=traj.top)
        edict4 = pt.energy_decomposition(traj=[traj[:5], traj[5:]],
                                         mm_options=options,
                                         prmtop=topfile,
                                         top=traj.top)
        edict5 = pt.energy_decomposition(traj=[traj[:5], traj(start=5)],
                                         mm_options=options,
                                         prmtop=topfile,
                                         top=traj.top)
        # test dtype
        dslist = pt.energy_decomposition(traj=[traj, ],
                                         mm_options=options,
                                         prmtop=topfile,
                                         top=traj.top,
                                         dtype='dataset')
        assert edict == edict2
        assert edict == edict3
        assert edict == edict4
        assert sorted(dslist.to_dict()) == sorted(edict)
Example #21
0
def main(argv):
    args = sys.argv

    native = ''
    outfile = ''

    try:
        opts, args=getopt.getopt(sys.argv[1:], "ho:n:o:", ["in:file:n=", "out:file:scorefile="])
    except getopt.GetoptError:
        print('Unknown flag given.\nKnown flags:\n\t-h\n\t-n <native>')
        sys.exit()

    for opt, arg in opts:
        if opt == '-h':
            print('Something.py --in:file:s <input_pdb_id> --out:file:scorefile <output_filename>')
            sys.exit()
        elif opt in ("-n", "--in:file:n"):
            native = arg
        elif opt in ("-o", "--out:file:scorefile"):
            outfile = arg

    if native == '':
        print('No native rst7 supplied.')
        sys.exit()

    if outfile == '':
        outfile = 'Scores.sc'

    print( "===== Native RST7: %s =====" % native )

    os.chdir(PATH_TO_DECOYDISC)
    min_decoys = os.popen('ls min*.rst7').readlines()  ## List of rst7s ["<rst7_1>\n", "<rst7_2>\n", ...]
    for m in range(len(min_decoys)):
        min_decoys[m] = min_decoys[m].rstrip()

    if native in min_decoys:
        min_decoys.remove(native)

    print("== Analyzing %i mols==" % len(min_decoys))

    min_decoys.insert(0, native)
    parmfile = '_'.join(native.split('_')[1:]).rstrip('rst7') + 'parm7'

    print("\t=== Loading Trajectories ===")
    traj = pt.iterload(min_decoys, parmfile)

    print("\t=== Getting RMSDs ===")
    ca_rmsd_data = pt.rmsd(traj, mask=['@CA'])

    print("\t=== Getting Energy Decomposition ===")
    energy_data = pt.energy_decomposition(traj, igb=8)
    print("\t\tFinished")

    with open(outfile,'w') as scorefile:
        header = 'pdb\t'
        for s in energy_data.keys():
            header += s + '\t'
        header += 'rmsd\n'
        scorefile.write(header)

        for pdb_index in range(len(min_decoys)):
            scoreline = min_decoys[pdb_index]+'\t'
            for s in energy_data.keys():
                scoreline += '%s\t' % str(energy_data[s][pdb_index])
            scoreline += '%s\n' % str(ca_rmsd_data[pdb_index])
            scorefile.write(scoreline)
Example #22
0
    traj = pt.iterload("./data/Ala3/Ala3.crd", "./data/Ala3/Ala3.top")

    print(traj.n_atoms, traj.top.n_residues)
    print(pt.multidihedral(traj).to_dict())

    t0 = traj[:1]
    deg_ene = []

    flist = []

    for deg in range(-180, 180, 5):
        pt.rotate_dihedral(t0, "custom:3:omega:" + str(deg))

        flist.append(t0[0].copy())

        en = pt.energy_decomposition(t0, igb=8,
                                     prmtop=traj.top.filename)['dihedral'][0]
        deg_ene.append((deg, en))

    arr = np.array(deg_ene).T

    pt.write_traj("test.pdb",
                  flist,
                  top=traj.top,
                  overwrite=True,
                  options='model')

    arr[1] = arr[1] - np.min(arr[1])
except ImportError:
    pass
flist = []

try:
    import sander
    import parmed
    # scan from -180 to 180, every 5 deg
    # calculate dihedral energy for each conformation
    #
    for deg in range(-180, 180, 5):
        pt.rotate_dihedral(t0, "custom:3:omega:" + str(deg))

        flist.append(t0[0].copy())

        en = pt.energy_decomposition(t0,
                                     igb=8,
                                     verbose=False,
                                     parm=traj.top.filename)['dihedral'][0]
        print(deg, en)
        deg_ene.append((deg, en))

    arr = np.array(deg_ene).T

    print(len(flist))

    # write multiple pdb to a single file to visualize
    # rotation with vmd.
    pt.write_traj("output/test.pdb", flist,
                  top=traj.top,
                  overwrite=True,
                  options='model')
    elif 'decoys.set2' in pdb:
        pdb_dirs[index] = pdb.replace('decoys.set2', 'decoys.set2.init')
    else:
        pdb_dirs[index] = pdb

# get min filenames
_min_files = [pdb_dir + '/no_restraint/' + 'min_NoH_' + x
              for pdb_dir, x in zip(pdb_dirs, df[2])]

end = '_0001'
min_files = []

for mf in _min_files:
    if '0001_0001' in mf:
        min_files.append(mf.replace('0001_0001', '0001') + '.rst7')
    elif '0002_0001' in mf:
        min_files.append(mf.replace('0002_0001', '0002') + '.rst7')
    else:
        min_files.append(mf)

epots = []

for pdb_dir, mf in zip(pdb_dirs, min_files):
    if os.path.exists(mf):
        parmfile = glob(pdb_dir + '/*.parm7')[0]
        traj = pt.iterload(mf, parmfile)
        epots.append(pt.energy_decomposition(traj, igb=8)['tot'][0])
    else:
        epots.append(None)
pt.to_pickle(epots, 'epots.pk')
Example #25
0
# import MPI to get rank
from mpi4py import MPI
import pytraj as pt
from pytraj.testing import aa_eq

try:
    import sander
    comm = MPI.COMM_WORLD
    # end. you are free to update anything below here

    # split remd.x.000 to N cores and do calc_surf in parallel
    root_dir = "../../tests/data/"
    traj_name = root_dir + "tz2.nc"
    parm_name = root_dir + "tz2.parm7"

    # load to TrajectoryIterator
    traj = pt.iterload(traj_name, parm_name)
    inp = sander.gas_input(8)

    # gather the data
    # if rank != 0: data is None
    data = pt.pmap_mpi(pt.energy_decomposition, traj, mm_options=inp)

    if comm.rank == 0:
        # make sure to reproduce serial output
        serial_data = pt.energy_decomposition(traj, mm_options=inp)
        aa_eq(pt.tools.dict_to_ndarray(data), pt.tools.dict_to_ndarray(serial_data))
except ImportError:
    print('does not have sander. skip this example')
Example #26
0
    else:
        pdb_dirs[index] = pdb

# get min filenames
_min_files = [
    pdb_dir + '/no_restraint/' + 'min_NoH_' + x
    for pdb_dir, x in zip(pdb_dirs, df[2])
]

end = '_0001'
min_files = []

for mf in _min_files:
    if '0001_0001' in mf:
        min_files.append(mf.replace('0001_0001', '0001') + '.rst7')
    elif '0002_0001' in mf:
        min_files.append(mf.replace('0002_0001', '0002') + '.rst7')
    else:
        min_files.append(mf)

epots = []

for pdb_dir, mf in zip(pdb_dirs, min_files):
    if os.path.exists(mf):
        parmfile = glob(pdb_dir + '/*.parm7')[0]
        traj = pt.iterload(mf, parmfile)
        epots.append(pt.energy_decomposition(traj, igb=8)['tot'][0])
    else:
        epots.append(None)
pt.to_pickle(epots, 'epots.pk')
Example #27
0
import pytraj as pt
import numpy as np

traj = pt.iterload("RAN.rst7", "RAN.parm7")

print(traj.n_atoms, traj.top.n_residues)
print(pt.calc_chin(traj))

t0 = traj[:1]
deg_ene = []

flist = []

for deg in range(-180, 180, 5):
    pt._rotate_dih(t0, dihtype='chin', deg=deg, resid='1')
    flist.append(t0[0].copy())

en = pt.energy_decomposition(flist,
                             top=traj.top,
                             igb=8,
                             parm='./RAN.parm7')['dihedral']

chin = pt.calc_chin(flist, top=traj.top).values
en = en - en.min()

from matplotlib import pyplot as plt
plt.plot(chin, en, '--bo')
plt.show()
Example #28
0
def main(argv):
    args = sys.argv

    native = ''
    outfile = ''

    try:
        opts, args = getopt.getopt(sys.argv[1:], "ho:n:o:",
                                   ["in:file:n=", "out:file:scorefile="])
    except getopt.GetoptError:
        print('Unknown flag given.\nKnown flags:\n\t-h\n\t-n <native>')
        sys.exit()

    for opt, arg in opts:
        if opt == '-h':
            print(
                'Something.py --in:file:s <input_pdb_id> --out:file:scorefile <output_filename>'
            )
            sys.exit()
        elif opt in ("-n", "--in:file:n"):
            native = arg
        elif opt in ("-o", "--out:file:scorefile"):
            outfile = arg

    if native == '':
        print('No native rst7 supplied.')
        sys.exit()

    if outfile == '':
        outfile = 'Scores.sc'

    print("===== Native RST7: %s =====" % native)

    os.chdir(PATH_TO_DECOYDISC)
    min_decoys = os.popen('ls min*.rst7').readlines(
    )  ## List of rst7s ["<rst7_1>\n", "<rst7_2>\n", ...]
    for m in range(len(min_decoys)):
        min_decoys[m] = min_decoys[m].rstrip()

    if native in min_decoys:
        min_decoys.remove(native)

    print("== Analyzing %i mols==" % len(min_decoys))

    min_decoys.insert(0, native)
    parmfile = '_'.join(native.split('_')[1:]).rstrip('rst7') + 'parm7'

    print("\t=== Loading Trajectories ===")
    traj = pt.iterload(min_decoys, parmfile)

    print("\t=== Getting RMSDs ===")
    ca_rmsd_data = pt.rmsd(traj, mask=['@CA'])

    print("\t=== Getting Energy Decomposition ===")
    energy_data = pt.energy_decomposition(traj, igb=8)
    print("\t\tFinished")

    with open(outfile, 'w') as scorefile:
        header = 'pdb\t'
        for s in energy_data.keys():
            header += s + '\t'
        header += 'rmsd\n'
        scorefile.write(header)

        for pdb_index in range(len(min_decoys)):
            scoreline = min_decoys[pdb_index] + '\t'
            for s in energy_data.keys():
                scoreline += '%s\t' % str(energy_data[s][pdb_index])
            scoreline += '%s\n' % str(ca_rmsd_data[pdb_index])
            scorefile.write(scoreline)
Example #29
0
    print(traj.n_atoms, traj.top.n_residues)
    print(pt.multidihedral(traj).to_dict())

    t0 = traj[:1]
    deg_ene = []

    flist = []

    for deg in range(-180, 180, 5):
        pt.rotate_dihedral(t0, "custom:3:omega:" + str(deg))

        flist.append(t0[0].copy())

        en = pt.energy_decomposition(t0,
                                     igb=8,
                                     prmtop=traj.top.filename)['dihedral'][0]
        deg_ene.append((deg, en))

    arr = np.array(deg_ene).T

    pt.write_traj("test.pdb",
                  flist,
                  top=traj.top,
                  overwrite=True,
                  options='model')

    arr[1] = arr[1] - np.min(arr[1])
except ImportError:
    pass
Example #30
0
# mmgbsa EGB should match (or be close): -402.71625 kcal/mol
# for first 10 frames

import pytraj as pt 
traj = pt.iterload('tz2.nc', 'tz2.parm7')

gb = pt.energy_decomposition(traj, igb=8)['gb']

print(gb[0])
Example #31
0
# import MPI to get rank
from mpi4py import MPI
import pytraj as pt
from pytraj.testing import aa_eq

try:
    import sander
    comm = MPI.COMM_WORLD
    # end. you are free to update anything below here

    # split remd.x.000 to N cores and do calc_surf in parallel
    root_dir = "../../tests/data/"
    traj_name = root_dir + "tz2.nc"
    parm_name = root_dir + "tz2.parm7"

    # load to TrajectoryIterator
    traj = pt.iterload(traj_name, parm_name)
    inp = sander.gas_input(8)

    # gather the data
    # if rank != 0: data is None
    data = pt.pmap_mpi(pt.energy_decomposition, traj, mm_options=inp)

    if comm.rank == 0:
        # make sure to reproduce serial output
        serial_data = pt.energy_decomposition(traj, mm_options=inp)
        aa_eq(pt.tools.dict_to_ndarray(data),
              pt.tools.dict_to_ndarray(serial_data))
except ImportError:
    print('does not have sander. skip this example')