Skip to content

Instantly share code, notes, and snippets.

@leelasd
Created April 22, 2018 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leelasd/84327bd40625d9cca6c66a1e2eecd100 to your computer and use it in GitHub Desktop.
Save leelasd/84327bd40625d9cca6c66a1e2eecd100 to your computer and use it in GitHub Desktop.
Select Atoms within a Region
import numpy as np
import mdtraj as md
import matplotlib
import pandas as pd
def GetResiduesWithinNang(traj,radius=20):
top = traj.topology
ligand = top.select('resname JLJ')
prot = top.select("protein and mass>2")
#def SelectWithinNangs(prot,ligand):
ap = []
for i in prot:
for j in ligand: ap.append([i,j])
ap = np.array(ap)
print(ap.shape)
distance = md.compute_distances(traj,ap)
df = pd.DataFrame(ap)
df.columns = ['PROT','LIGA']
df['DIST']=distance[0]
reg = df[df.DIST<=radius*0.1]
reg['RES_CODE'] = [top.atom(i).residue.index for i in reg.PROT]
## Expand atomselection to complete residues
all_atoms = []
for res in reg.RES_CODE.unique():
for at in top.residue(res).atoms: all_atoms.append(at.index)
return all_atoms
traj = md.load_pdb('first.pdb')
print(GetResiduesWithinNang(traj))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment