def calculateSASA(trajectory, topology, res_name):
    """
        Calculate the SASA of a ligand in a trajectory

        :param trajectory: Name of the trajectory file
        :type trajectory: str
        :param topology: Topology of the trajectory (needed for non-pdb trajs)
        :type topology: str
        :param res_name: Ligand resname
        :type res_name: str
    """
    utilities.print_unbuffered("Processing", trajectory)
    t = md.load(trajectory, top=topology)
    t.remove_solvent(inplace=True)
    res_atoms = t.top.select("resname '%s'" % res_name)
    if not len(res_atoms):
        raise ValueError("Nothing found using resname %s" % res_name)
    t2 = t.atom_slice(res_atoms)
    for atom in t2.top.atoms:
        # mdtraj complains if the ligand residue index is not 0 when
        # isolated
        atom.residue.index = 0
    res_index = t.top.atom(res_atoms[0]).residue.index
    sasa = md.shrake_rupley(t, mode="residue")
    sasa_empty = md.shrake_rupley(t2, mode="residue")
    return sasa[:, res_index] / sasa_empty[:, 0]
Пример #2
0
def accessible_surface_area(traj, nanoparticle_radius, probe_radius=0.25):
    radii_exchange = {'C': nanoparticle_radius, 'N': MMM_sigma/2, 'O': MME_sigma/2}

    sasa = md.shrake_rupley(traj, mode='residue', change_radii=radii_exchange,
                            probe_radius=probe_radius, n_sphere_points=1000)

    return np.column_stack((traj.time, sasa[:,0]))
Пример #3
0
def main():
    import mdtraj as md
    import pickle
    args = parser()
    trj_file, top = args.traj, args.top
    probe_radius, n_sphere_points = args.probe_radius, args.n_sphere_points
    traj = md.load(trj_file, top=top)
    print(traj)

    keys = get_residue_tag(top)
    print(keys)
    trj_sasa = md.shrake_rupley(
        traj,
        probe_radius=probe_radius,
        n_sphere_points=n_sphere_points,  # the default value of gmx sasa is 24 
        mode='residue')

    print('sasa data shape', trj_sasa.shape)
    print(len(trj_sasa[0, :]))

    i = 0
    sasa_dict = {}
    for key in keys:
        sasa_dict[key] = trj_sasa[:, i]
        i += 1
    fout1 = open('dict_sasa.pkl', 'wb')
    pickle.dump(sasa_dict, fout1)
Пример #4
0
def run(project, atom_indices=None, traj_fn = 'all'):

    n_atoms = project.load_conf().n_atoms

    if traj_fn.lower() == 'all':

        SASA = np.ones((project.n_trajs, np.max(project.traj_lengths), n_atoms)) * -1

        for traj_ind in xrange(project.n_trajs):
            traj_asa = []
            logger.info("Working on Trajectory %d", traj_ind)
            traj_fn = project.traj_filename(traj_ind)
            chunk_ind = 0
            for traj_chunk in md.iterload(traj_fn, atom_indices=atom_indices, chunk=1000):
                traj_asa.extend(md.shrake_rupley(traj_chunk))
                chunk_ind += 1
            SASA[traj_ind, 0:project.traj_lengths[traj_ind]] = traj_asa

    else:
        traj_asa = []
        for traj_chunk in Trajectory.enum_chunks_from_lhdf( traj_fn, AtomIndices=atom_indices ):
            traj_asa.extend( asa.calculate_asa( traj_chunk ) )

        SASA = np.array(traj_asa)

    return SASA
def main():
    import numpy as np
    args = parser()
    file_names = args.file
    for file_name in file_names:
        traj = md.load(file_name, top=file_name)

        keys = get_residue_tag(file_name)
        print(keys)
        trj_sasa = md.shrake_rupley(
            traj,
            probe_radius=0.14,
            n_sphere_points=100,  # the default value of gmx sasa is 24 
            mode='residue')

        print('sasa data shape', trj_sasa.shape)

        i = 0
        sasa_dict = {}
        for key in keys:
            sasa_dict[key] = trj_sasa[:, i]
            i += 1

        name = file_name.split('.')[0].upper()
        np.savetxt(f'sasa_{name}.dat',
                   trj_sasa,
                   fmt='%.2f',
                   header=f'SASA in isolation of {name}')
Пример #6
0
def test_single(pdb_id):
    file_name = join(data_dir, pdb_id + ".pdb")

    # Single atom SASA, compare with MDTraj
    file = pdb.PDBFile()
    file.read(file_name)
    array = file.get_structure(model=1)
    sasa = struc.sasa(array, vdw_radii="Single", point_number=5000)

    from biotite.structure.info.radii import _SINGLE_RADII as radii
    import mdtraj
    # Use the same atom radii
    radii = {
        element.capitalize(): radius / 10
        for element, radius in radii.items()
    }
    traj = mdtraj.load(file_name)
    # Conversion from nm^2 to A^2
    sasa_exp = mdtraj.shrake_rupley(
        traj, change_radii=radii, n_sphere_points=5000)[0] * 100

    # Assert that more than 90% of atoms
    # have less than 10% SASA difference
    assert np.count_nonzero(np.isclose(sasa, sasa_exp, rtol=1e-1,
                                       atol=1e-1)) / len(sasa) > 0.9
    # Assert that more than 98% of atoms
    # have less than 1% SASA difference
    assert np.count_nonzero(np.isclose(sasa, sasa_exp, rtol=1e-2,
                                       atol=1e-1)) / len(sasa) > 0.98
Пример #7
0
def _test_sasa_featurizer(t, value):
    sasa = md.shrake_rupley(t)
    rids = np.array([a.residue.index for a in t.top.atoms])

    for i, rid in enumerate(np.unique(rids)):
        mask = (rids == rid)
        eq(value[:, i], np.sum(sasa[:, mask], axis=1))
Пример #8
0
def _test_sasa_featurizer(t, value):
    sasa = md.shrake_rupley(t)
    rids = np.array([a.residue.index for a in t.top.atoms])

    for i, rid in enumerate(np.unique(rids)):
        mask = (rids == rid)
        eq(value[:, i], np.sum(sasa[:, mask], axis=1))
Пример #9
0
def get_sasa():
    import mdtraj as md
    save_dir = f'/home/hyang/bio/erf/data/design/cullpdb_val_deep/'
    protein_sample = pd.read_csv(
        '/home/hyang/bio/erf/data/design/cullpdb_val_deep/sample.csv')
    pdb_selected = protein_sample['pdb'].values
    for p in pdb_selected:
        pdb_id = p[:4]
        structure = md.load(
            f'/home/hyang/bio/openmm/data/{pdb_id}/production_T300.pdb')
        topology = structure.topology
        trj = md.load(
            f'/home/hyang/bio/openmm/data/{pdb_id}/production_T300.dcd',
            top=topology)
        topology.create_standard_bonds()
        trj = trj.remove_solvent()
        sasa = md.shrake_rupley(trj, mode='residue')
        sasa *= 100
        fig = pl.figure()
        for i in range(sasa.shape[0]):
            pl.plot(sasa[i])
        pl.xlabel('Residue Number')
        pl.ylabel('SASA (A^2)')
        pl.savefig(f'{save_dir}/{p}_sasa.pdf')
        pl.close(fig)

        df = pd.read_csv(f'{save_dir}/{p}_bead.csv')
        df['sasa'] = np.mean(sasa, axis=0)
        df.to_csv(f'{save_dir}/{p}_bead_sasa.csv')
Пример #10
0
    def _test_atom_group(t, value):
        sasa = md.shrake_rupley(t, mode="atom")
        rids = np.array([a.residue.index for a in t.top.atoms])

        for i, rid in enumerate(np.unique(rids)):
            mask = rids == rid
            eq(value[:, i], np.sum(sasa[:, mask], axis=1))
def run(project, atom_indices=None, traj_fn='all'):

    n_atoms = project.load_conf().n_atoms

    if traj_fn.lower() == 'all':

        SASA = np.ones(
            (project.n_trajs, np.max(project.traj_lengths), n_atoms)) * -1

        for traj_ind in xrange(project.n_trajs):
            traj_asa = []
            logger.info("Working on Trajectory %d", traj_ind)
            traj_fn = project.traj_filename(traj_ind)
            chunk_ind = 0
            for traj_chunk in md.iterload(traj_fn,
                                          atom_indices=atom_indices,
                                          chunk=1000):
                traj_asa.extend(md.shrake_rupley(traj_chunk))
                chunk_ind += 1
            SASA[traj_ind, 0:project.traj_lengths[traj_ind]] = traj_asa

    else:
        traj_asa = []
        for traj_chunk in Trajectory.enum_chunks_from_lhdf(
                traj_fn, AtomIndices=atom_indices):
            traj_asa.extend(asa.calculate_asa(traj_chunk))

        SASA = np.array(traj_asa)

    return SASA
 def calc_sasa(traj, chain=0, featurizer=None):
     small_traj = traj.atom_slice(
         atom_indices=featurizer.select(f'chainid == {chain}'))
     res = md.shrake_rupley(small_traj,
                            probe_radius=0.14,
                            n_sphere_points=960,
                            mode='residue')
     return res
Пример #13
0
def get_sasa(cluster_indices, type_of_clustering):
    sasa_of_states = {}
    max_sasa = 0.0
    for index in cluster_indices:
        f = md.load_pdb(type_of_clustering + "_" + str(index) + ".pdb")
        sasa = md.shrake_rupley(f)
        total_sasa = sasa.sum(axis=1)
        sasa_of_states[index] = float(total_sasa)
    return sasa_of_states
Пример #14
0
	def compute_SASA(self, PDB):
	        """
		compute the Solvent Accessible Surface Area with MDTraj. The Shrake Rupley algorithm is relatively expensive
		and difficult to code, so I borrowed from MDTraj.

	        """
		struc = md.load(PDB)
		self.SASA.append(md.shrake_rupley(struc).sum(axis=1)[0])
		return None
Пример #15
0
def get_sasa(trajectory, topology, coreruns=10):
    """
    Calculates Solvent Accessible Surface area, currently step size of trajectory is reduced due to memory limits
    :param trajectory: string, path to trajectory location
    :param topology: string, path to topology location
    :param step: int, number of operations to split between serial runs to prevent memory overload
    :return: list, mean SASA for each residue amide hydrogen
    """
    print('Calculating SASA')
    print('step index')
    traj = md.load(trajectory, top=topology)

    topology = traj.topology

    max_frames = int(traj.n_frames)

    mem_max = 15000  #max number of frames per serial run, set due to memory limits
    stepsize = int(max_frames / mem_max)
    print('stepsize:', stepsize)

    if coreruns * mem_max > max_frames:
        print('ERROR')

    sasaoutputavg = pd.DataFrame()
    sasaoutputmax = pd.DataFrame()
    sasaoutput_all = pd.DataFrame()

    for i in range(0, coreruns):
        sasa = md.shrake_rupley(traj[0 + i:max_frames:stepsize],
                                probe_radius=0.014,
                                n_sphere_points=960,
                                mode='atom')
        amidesasa = sasa[:, topology.select('name H')]
        print(amidesasa)

        amidesasa_all = pd.DataFrame(amidesasa)
        np.savetxt('amidesasa_all', amidesasa_all)
        amidesasaavg = pd.DataFrame(amidesasa.mean(axis=0),
                                    columns=[str(f"sasa{i}_mean")])
        amidesasamax = pd.DataFrame(amidesasa.max(axis=0),
                                    columns=[str(f"sasa{i}_max")])

        d = f"sasa{i}"

        sasaoutput_all = pd.concat((sasaoutput_all, amidesasa_all), axis=0)
        sasaoutputavg = pd.concat((sasaoutputavg, amidesasaavg), axis=1)
        sasaoutputmax = pd.concat((sasaoutputmax, amidesasamax), axis=1)

        np.savetxt('amidesasa_all.out', sasaoutput_all)
        sasaoutputavg = sasaoutputavg.mean(axis=1)
        np.savetxt('amidesasaavg_allframe.out', sasaoutputavg)
        sasaoutputmax = sasaoutputmax.mean(axis=1)
        np.savetxt('amidesasamax_allframe.out', sasaoutputmax)

    return (sasaoutputavg, sasaoutputmax)
Пример #16
0
def sasa_atoms(macromolecule, probe_radius=0.227, n_sphere_points=5000):
    #0.227 rdw NA
    topology_mdtraj = md.Topology.from_openmm(macromolecule.topology)
    positions_mdtraj = macromolecule.positions._value
    aux_traj = md.Trajectory(positions_mdtraj, topology_mdtraj)
    sasa = md.shrake_rupley(aux_traj,
                            probe_radius=probe_radius,
                            n_sphere_points=n_sphere_points,
                            mode='atom')

    return sasa
Пример #17
0
def compute_sasa(traj):
    # define number of frames and atoms
    N = traj.xyz.shape[0]
    M = traj.xyz.shape[1]

    # compute solvent accessible surface area for each frame for each atom
    sasa = np.zeros((N, M), dtype=np.float32)
    for k in tqdm(range(traj.xyz.shape[0])):
        sasa[k] = md.shrake_rupley(traj[k]).ravel()

    return sasa
Пример #18
0
 def SASA(self):
     for seedi in range(len(self.FNSeeds)):
         self.SASAs[seedi] = md.shrake_rupley(self.trajectories[seedi],
                                              probe_radius=0.14,
                                              mode='residue',
                                              get_mapping=False)
         nframes = (self.SASAs[seedi]).shape[0]
         nres = (self.SASAs[seedi]).shape[1]
         self.totSASAs[seedi] = np.zeros((nframes))
         for i in range(nframes):
             self.totSASAs[seedi][i] = np.sum(self.SASAs[seedi][i])
         print("SASA:")
         print((self.totSASAs[seedi]).shape)
def calculateSASA(trajectory, topology, res_name):
    """
        Calculate the SASA of a ligand in a trajectory

        :param trajectory: Name of the trajectory file
        :type trajectory: str
        :param topology: Topology of the trajectory (needed for non-pdb trajs)
        :type topology: str
        :param res_name: Ligand resname
        :type res_name: str
    """
    t = md.load(trajectory, top=topology)
    res_atoms = t.top.select("resname '%s'" % res_name)
    t2 = t.atom_slice(res_atoms)
    for atom in t2.top.atoms:
        # mdtraj complains if the ligand residue index is not 0 when
        # isolated
        atom.residue.index = 0
    res_index = t.top.atom(res_atoms[0]).residue.index
    sasa = md.shrake_rupley(t, mode="residue")
    sasa_empty = md.shrake_rupley(t2, mode="residue")
    return sasa[:, res_index] / sasa_empty[:, 0]
Пример #20
0
def map_sasa_core(trajectoryfile, topologyfile, probe_radius):
    import mdtraj as md

    print("computing using threading ", probe_radius, "nm sasa for",
          trajectoryfile, "using topology", topologyfile)

    if topologyfile:
        trj = md.load(trajectoryfile, top=topologyfile)
    else:
        trj = md.load(trajectoryfile)
    print("loaded", trajectoryfile, 'with topology', topologyfile)
    sasas = md.shrake_rupley(trj, probe_radius=probe_radius)

    return sasas
Пример #21
0
def test_sasa_4():
    def _test_atom_group(t, value):
        sasa = md.shrake_rupley(t, mode='atom')
        rids = np.array([a.residue.index for a in t.top.atoms])

        for i, rid in enumerate(np.unique(rids)):
            mask = (rids == rid)
            eq(value[:, i], np.sum(sasa[:, mask], axis=1))

    t = md.load(get_fn('frame0.h5'))
    value = md.shrake_rupley(t, mode='residue')
    assert value.shape == (t.n_frames, t.n_residues)
    yield lambda: _test_atom_group(t, value)

    # scramle the order of the atoms, and which residue each is a
    # member of
    df, bonds = t.top.to_dataframe()
    df['resSeq'] = np.random.permutation(df['resSeq'])
    df['resName'] = df['resSeq']
    t.top = md.Topology.from_dataframe(df, bonds)

    value = md.shrake_rupley(t, mode='residue')
    yield lambda: _test_atom_group(t, value)
    def compute_sasa(self, radius=0.14, mode="residue"):
        """
        Compute the solvent accessible surface area of each atom or residue in each simulation frame

        :param radius: The radius of the probe, in nm
        :param mode: In mode == atom the extracted areas are resolved peratom In mode == residue,
        this is consolidated down to the per-residue SASA by summing over the atoms in each residue
        :return: The accessible surface area of each atom or residue in every frame. If mode == atom,
        the second dimension will index the atoms in the trajectory,
        whereas if mode == residue, the second dimension will index the residues. ( np.array, shape=(n_frames, n_features)

        """

        return md.shrake_rupley(self.traj, probe_radius=radius, mode=mode)
Пример #23
0
def test_sasa_4():
    def _test_atom_group(t, value):
        sasa = md.shrake_rupley(t, mode='atom')
        rids = np.array([a.residue.index for a in t.top.atoms])

        for i, rid in enumerate(np.unique(rids)):
            mask = (rids == rid)
            eq(value[:, i], np.sum(sasa[:, mask], axis=1))

    t = md.load(get_fn('frame0.h5'))
    value = md.shrake_rupley(t, mode='residue')
    assert value.shape == (t.n_frames, t.n_residues)
    yield lambda: _test_atom_group(t, value)

    # scramle the order of the atoms, and which residue each is a
    # member of
    df, bonds = t.top.to_dataframe()
    df['resSeq'] = np.random.permutation(df['resSeq'])
    df['resName'] = df['resSeq']
    t.top = md.Topology.from_dataframe(df, bonds)

    value = md.shrake_rupley(t, mode='residue')
    yield lambda: _test_atom_group(t, value)
Пример #24
0
def calc_sasa(trajectory, parallel=True, parallel_way='multiprocessing', n_sphere_points=960):
    if parallel is False:
        sasa = md.shrake_rupley(trajectory, n_sphere_points=n_sphere_points)

        print(trajectory)
        print('sasa data shape', sasa.shape)

        total_sasa = sasa.sum(axis=1)
        print('total sasa shape ', total_sasa.shape)
    else:

        if parallel_way == 'ipyparallel':
            # TODO start by for single machine ipcluster start -n 4
            print('Parallel calculation Haha')
            # from IPython.parallel import Client

            from ipyparallel import Client

            c = Client()

            results = c[:].map(md.shrake_rupley, trajectory)
            sasa_list = results.get()

            sasa = np.vstack(sasa_list)
            # sasa_temp = [x[0] for x in sasa_list]
            # sasa = np.array(sasa_temp)
            # print('sasa shape ', sasa.shape)

            total_sasa = sasa.sum(axis=1)
            print('total sasa shape ', total_sasa.shape)
        else:
            import multiprocessing
            num_proc = multiprocessing.cpu_count()
            print('Your number of CPUs is ', num_proc)

            pool = multiprocessing.Pool(num_proc)

            results = pool.map(md.shrake_rupley, trajectory)
            sasa_list = results

            sasa = np.vstack(sasa_list)
            # sasa_temp = [x[0] for x in sasa_list]
            # sasa = np.array(sasa_temp)
            # print('sasa shape ', sasa.shape)

            total_sasa = sasa.sum(axis=1)
            print('total sasa shape ', total_sasa.shape)

    return sasa, total_sasa
Пример #25
0
def calc_sasa(ag,
              normalize=True,
              change_radii: dict = None,
              probe_radius=0.14):
    traj = _load_traj(ag)
    vdw_radii = VDW_RADII.copy()
    if change_radii is not None:
        vdw_radii.update(change_radii)
    max_sasa = {k: 4 * math.pi * r * r * 0.01 for k, r in vdw_radii.items()}
    atom_sasa = md.shrake_rupley(traj,
                                 change_radii=change_radii,
                                 probe_radius=probe_radius)[0]
    if normalize:
        atom_sasa /= np.array([max_sasa[x] for x in ag.getElements()])
    return atom_sasa
Пример #26
0
def sasa_mdtraj(pdbfile):
    """
        Calculate the SASA per residue using the Shrake & Rupley algorithm [1]
        as implemented in mdtraj [2]. Return values in angstrom^2.
        [1] A. Shrake and J. A. Rupley, "Environment and exposure to solvent 
            of protein atoms. Lysozyme and insulin", Journal of Molecular 
            Biology, vol. 79, no. 2, pp. 351-371, 1973.
        [2] R. T. McGibbon et al., "MDTraj: A Modern Open Library for the 
            Analysis of Molecular Dynamics Trajectories", Biophysical Journal, 
            vol. 109, no. 8, pp. 1528-1532, 2015.
    """
    pdb = mdtraj.load(pdbfile)
    res = [residue.name for residue in pdb.topology.residues]
    sasa = mdtraj.shrake_rupley(pdb, mode='residue')[0] * 100.0
    return res, sasa
Пример #27
0
    def sasa_calculation(system_specs, specs):
        """
        

        Parameters
        ----------
        system_specs : TYPE
            DESCRIPTION.
        specs : TYPE
            DESCRIPTION.

        Returns
        -------
        TYPE
            DESCRIPTION.

        """

        (trajectory, topology, results_folder, name) = system_specs
        (selection, start, stop, timestep, stride, units_x, units_y, task,
         store_traj, subset) = specs
        names, indexes, column_index = Featurize.df_template(system_specs,
                                                             unit=[units_y])
        traj = Trajectory.Trajectory.loadTrajectory(system_specs, specs)

        if traj != None:

            atom_indices = traj.topology.select(selection)
            sasa = md.shrake_rupley(traj[start:stop:stride],
                                    traj[start:stop:stride],
                                    mode='residue')
            print(sasa)
            rows = rows = pd.Index(np.arange(0, len(sasa)), name='Index')
            column_index = pd.MultiIndex.from_product(indexes, names=names)

            df_system = pd.DataFrame(
                sasa, columns=column_index,
                index=rows)  #index=np.arange(start, stop, stride)
            #df_system.index.rename ='Index'

            #Remove non-sense
            #df_system=df_system.mask(df_system > 90)

            return df_system

        else:
            return pd.DataFrame()
Пример #28
0
def SASA(grofile, trajfile, frame_iterator):
    """
    TOO SLOW | NOT COMPLETED
    Calculate the SASA - Solvent Accessible Surface Area
    """

    traj = mdtraj.load(trajfile, top=grofile)

    sasa = mdtraj.shrake_rupley(traj[frame_iterator],
                                probe_radius=0.14,
                                n_sphere_points=960,
                                mode='residue',
                                change_radii=None,
                                get_mapping=True)

    print(sasa)

    return sasa
    def run_SASA(self):
        PROBE_RADIUS, N_SPHERE_POINTS = 0.14, 100
        print(self.__traj_data)

        def get_residue_tag():
            """
            Todo:
                I want to do this function by mdtraj instead of MDAnalysis
            Return:
                residue_tags: List; e.g, [PHE1A, ARG2A, ...]
            """
            from MDAnalysis import Universe 
            u = Universe(self.__ref)
            residue_tags = []
            nchains = len(set(u.select_atoms('protein').segids))
            print(f'n chains = {nchains}')
            for chain, resn, resi in zip(u.residues.segids, u.residues.resnames, u.residues.resids):
            
                if chain == 'SYSTEM': 
                    self.chain = chain.replace('SYSTEM', 'A') # self.chain should have default vaule in __init__
                else:
                    self.chain = chain
                 
                residue_tags.append(resn + str(resi) + self.chain)
            
            return residue_tags

        keys = get_residue_tag()
        print(keys)
        
        sasa_matrix = md.shrake_rupley(self.__traj_data,
                                    probe_radius    = PROBE_RADIUS   ,
                                    n_sphere_points = N_SPHERE_POINTS,
                                    mode='residue')

        print('sasa data shape', sasa_matrix.shape)
        print(len(sasa_matrix[0,:]))
        
        ### Save a table storing sasa values
        df_sasa            = pd.DataFrame(sasa_matrix).round(4)
        df_sasa.columns    = keys    
        df_sasa.index.name = 'Frame No'
        df_sasa.to_csv(f'sasa_{self.__out_suffix}.csv')
        return df_sasa
Пример #30
0
def get_cluster_ids_for_start_and_end(initial_id, cluster_indices,
                                      type_of_clustering):
    start = initial_id  # initial frame is folded structure
    # choose structure with maximum SASA as unfolded structure
    unfolded_structure_cluster_id = start
    max_sasa = 0.0
    for index in cluster_indices:
        try:
            f = md.load_pdb(type_of_clustering + "_" + str(index) + ".pdb")
        except:
            continue
        sasa = md.shrake_rupley(f)
        total_sasa = sasa.sum(axis=1)
        if total_sasa > max_sasa:
            max_sasa = total_sasa
            unfolded_structure_cluster_id = index

    end = unfolded_structure_cluster_id
    #       end =  gaussian_cluster_ids[str(frames.shape[0] - 1)]
    return start, end
Пример #31
0
def get_sasa (molecular_system, target='atom', selection='all', structure_indices='all', syntaxis='MolSysMT',
          engine='MDTraj'):

    engine = digest_engine(engine)
    target = digest_target(target)

    if engine == 'MDTraj':

        from mdtraj import shrake_rupley

        tmp_item = convert(molecular_system, structure_indices=structure_indices, to_form='mdtraj.Trajectory')

        sasa_array = shrake_rupley(tmp_item, mode='atom') # tiene probe_radius y n_sphere_points

        if target=='atom':

            if selection is not 'all':

                atom_indices = select(molecular_system, selection=selection, syntaxis=syntaxis)
                sasa_array = sasa_array[:,atom_indices]

        else:

            sets_atoms = get(molecular_system, target=target, selection=selection, syntaxis=syntaxis, atom_index=True)

            n_sets = len(sets_atoms)
            n_structures = sasa_array.shape[0]

            new_sasa_array = np.empty([n_structures, n_sets], dtype='float')
            for ii in range(n_sets):
                new_sasa_array[:,ii] = sasa_array[:,sets_atoms[ii].astype(int)].sum(axis=1)
            sasa_array = new_sasa_array

        sasa_array = puw.quantity(sasa_array, 'nm**2')
        sasa_array = puw.standardize(sasa_array)

    else:

        raise NotImplementedError("Engine not implemented yet")

    return sasa_array
Пример #32
0
def featurize_sasa_individual(traj_file, bp_residues, anton, stride):
	print(traj_file)
	traj = md.load(traj_file, stride = stride)
	top = traj.topology
	protein_atoms = [a.index for a in top.atoms if a.residue.is_protein]
	traj = traj.atom_slice(protein_atoms)
	
	print(traj)

	#try:
	traj = fix_traj(traj)
	top = traj.topology
	sasa = md.shrake_rupley(traj, mode = 'atom')
	#except:
	#	return []

	bp_atoms = [a.index for a in top.atoms if a.residue.resSeq in bp_residues]
	print(np.shape(sasa))
	sasa = sasa[:, bp_atoms]
	total_sasa = sasa.sum(axis=1)
	return(total_sasa)
Пример #33
0
	def analyse_ligand_sasa(self):
		"""Analysis of ligand SASA."""
		i=0
		start = timer()
		if self.trajectory == []:
			self.trajectory = [self.topology_data.universe.filename]
		try:
			for traj in self.trajectory:
				new_traj = mdtraj.load(traj,top=self.topology_data.universe.filename)
				#Analyse only non-H ligand
				ligand_slice = new_traj.atom_slice(atom_indices=self.topology_data.universe.ligand_noH.ids)

				self.sasa = mdtraj.shrake_rupley(ligand_slice)
				self.atom_sasa[i]=self.assign_per_atom_sasa()
				i+=1
			self.total_sasa = self.get_total_per_atom_sasa()
		except KeyError as e:
			print "WARNING: SASA analysis cannot be performed due to incorrect atom names in"
			print "the topology ", e

		print "SASA: "+str(timer()-start)
Пример #34
0
def calc_sasa(chimera: Chimera = None, filename: str = None,
              probe_radius: float = 0.14, n_sphere_points: int = 960, sasa_type='total'):
    """

    Computes the Solvent Accessible Surface Area of the protein.
    This funcion uses the MDtraj shrake_rupley implementation as a basis.
    :param chimera: A Chimera object.
    :param filename: Path to a pdb file
    :param probe_radius: The radius of the probe, in nm.
    :param n_sphere_points: the number of points representing the sufrace of each atom. Higher values lead to more accuracy.
    :param sasa_type: Type of calculation to perform. To select from polar, apolar, or total.
    :return: areas: np.array containing the area of the chimera in Angstrom^2
    """
    sasa_types = ["polar", "apolar", "total"]
    if sasa_type not in sasa_types:
        raise ValueError(f"Invalid type. Expected one of {sasa_types}")
    if chimera and filename:
        raise ValueError("Only a Chimera object or the path to a pdb file must be specified")
    if not chimera and not filename:
        raise ValueError("At least a Chimera object or the path to a pdb file must be specified")
    if chimera:
        filename = "/tmp/structure.pdb"
        chimera.write(filename)

    polars = ['SER', 'THR', 'CYS', 'TYR', 'ASN', 'GLN', 'ASP', 'GLU', 'LYS', 'ARG', 'HIS']
    apolars = ['GLY', 'ALA', 'VAL', 'LEU', 'ILE', 'MET', 'TRP', 'PHE', 'PRO']
    structure = md.load(filename)
    if sasa_type == 'polar':
        indices = [index for index, residue in enumerate(structure.topology.residues) if residue.name in polars]
    elif sasa_type == 'apolar':
        indices = [index for index, residue in enumerate(structure.topology.residues) if residue.name in apolars]
    else:
        indices = [index for index, residue in enumerate(structure.topology.residues)]

    sasa = md.shrake_rupley(structure, probe_radius=probe_radius, n_sphere_points=n_sphere_points, mode="residue")
    area = sasa[0][indices].sum()
    logger.info(f"Area is {area} (nm)^2")
    return area
Пример #35
0
    def protein_calcs(self, struc):
        """
		Run calculations specified in self.calcs. Before running calculation, check
		to make sure it wasn't already done. If it was done before, load the data.

		"""
        coors = struc.xyz[0]
        CA_coors = struc.atom_slice(struc.topology.select('name CA'))[0].xyz[0]
        self.nres = struc.n_residues

        if 'Gyr' in self.calcs:
            L = sa_core.gyration_tensor(coors)
        if 'Rg' in self.calcs:
            #self.Rg.append(md.compute_rg(struc)[0])
            self.Rg.append(sa_core.compute_Rg(L))
        if 'Asph' in self.calcs:
            self.Asph.append(sa_core.compute_Asph(L))
        if 'EED' in self.calcs:
            self.EED.append(np.linalg.norm(CA_coors[0] - CA_coors[-1]))
        if 'SASA' in self.calcs:
            SASA = md.shrake_rupley(struc)
            self.SASA.append(SASA.sum(axis=1)[0])
        if 'cmaps' in self.calcs:
            dist = sa_core.contact_maps(CA_coors)
            self.cmaps.append(dist)
        if 'gcmaps' in self.calcs:
            self.gcmaps.append(sa_core.gremlin_contact_maps(dist))
        if 'SS' in self.calcs:
            self.SS.append(md.compute_dssp(struc))
        if 'flory' in self.calcs:
            self.fex.append(polymer.compute_flory(struc, self.nres))
        if 'rama' in self.calcs:
            self.dihedrals.append(rama.compute_phipsi(struc))
        if 'surface_contacts' in self.calcs:
            #self.resnames = [struc.atom_slice(struc.topology.select('name CA')).topology.atom(r).residue.name for r in range(self.nres)]
            # above was replaced by self.seq
            self.scmaps.append(sa_core.surface_contacts(struc, SASA))
        return None
Пример #36
0
    def from_mdtraj(self, a_traj, probe_radius=1.4, **kwargs):
        r"""Calculate solvent accessible surface for frames in a trajectory

        SASA units are Angstroms squared

        Parameters
        ----------
        a_traj: :class:`~mdtraj.Trajectory`
            mdtraj trajectory instance
        probe_radius: float
            The radius of the probe, in Angstroms
        kwargs: dict
            Optional arguments for the underlying mdtraj.shrake_rupley
            algorithm doing the actual SaSa calculation

        Returns
        -------
        self: :class:`~idpflex.properties.SaSa`
            Instantiated SaSa property object
        """
        self.y = 100 * mdtraj.shrake_rupley(
            a_traj, probe_radius=probe_radius / 10.0, **kwargs).sum(axis=1)[0]
        return self
Пример #37
0
 def partial_transform(self, traj):
     return md.shrake_rupley(traj, mode=self.mode, **self.kwargs)