.
from pymol import cmd
def clipped_by(at,v):
x,y,z = at.coord
nz = v[2]*(x-v[12])+v[5]*(y-v[13])+v[8]*(z-v[14])-v[11]
return nz > v[15] and nz < v[16]
def clipped(selection="all",state=1):
v = cmd.get_view()
return [ i.id for i in cmd.get_model(selection,state).atom if clipped_by(i,v) ]
def select_clipped(name='clipped', selection='all', state=1):
'''
DESCRIPTION
Select atoms between clipping planes
USAGE
select_clipped [name [, selection [, state]]]
'''
state = int(state)
cmd.select(name, 'none')
for model in cmd.get_object_list('(' + selection + ')'):
cmd.select_list('__tmp', model, clipped('(%s) and (%s)' % (model, selection), state))
cmd.select(name, '__tmp', merge=1)
cmd.delete('__tmp')
cmd.extend('select_clipped', select_clipped)