Created
March 6, 2024 17:38
-
-
Save matteoferla/fea8c998b98f1835f4f959949f9e1167 to your computer and use it in GitHub Desktop.
Slim down PSE file with superposed chains in multiple objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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