Skip to content

Instantly share code, notes, and snippets.

@matteoferla
Created March 6, 2024 17:38
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 matteoferla/fea8c998b98f1835f4f959949f9e1167 to your computer and use it in GitHub Desktop.
Save matteoferla/fea8c998b98f1835f4f959949f9e1167 to your computer and use it in GitHub Desktop.
Slim down PSE file with superposed chains in multiple objects
import numpy as np
import pymol2
token_resi = 25 # this present in all chains
filename = '👾👾👾.pse'
coords = {}
with pymol2.PyMOL() as pymol:
pymol.cmd.load('crysalin_lattice.pse')
for name in pymol.cmd.get_object_list():
for chain in pymol.cmd.get_chains(name):
coords[(name, chain)] = pymol.cmd.get_coords(f'{name} and chain {chain} and resi {token_resi} and name CA')
c = np.squeeze(np.array(list(coords.values())))
distances = np.sqrt( np.sum((c[:, np.newaxis, :] - c[np.newaxis, :, :]) ** 2, axis=-1) )
# get the ones that overlap in the upper triangle
close = np.tril(distances < 0.1) # triangle bool default is False
np.fill_diagonal(close, False)
names = list(coords.keys())
morituri = [names[a] for a in np.where(close)[0]]
with pymol2.PyMOL() as pymol:
pymol.cmd.load(filename)
for name, chain in morituri:
pymol.cmd.remove(f'{name} and chain {chain}')
pymol.cmd.save(filename.replace('.pse', '.slim.pse'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment