def _add_surface(surface): session = surface.session models = session.models if models.have_model(surface): # Reusing existing model. return # Check if request model id is already being used. model_id = surface.id if model_id: if models.have_id(model_id): from chimerax.core.errors import UserError id_string = '.'.join('%d'%i for i in model_id) raise UserError('Model id #%s already in use' % id_string) # If parent models don't exist create grouping models. p = None for i in range(1,len(model_id)): if not models.have_id(model_id[:i]): from chimerax.core.models import Model m = Model('shape', session) m.id = model_id[:i] models.add([m], parent = p) p = m # Add surface. models.add([surface])
def split(session, structures = None, chains = None, ligands = False, connected = False, atoms = None): ''' Partition atoms into separate structures. If only the first argument is given then those structures are split into a separate structure for each chain. If chains, ligands, connected, or atoms keywords are given then additional partitioning into smaller subsets is performed. Parameters ---------- Structures : Structures or None Structures to split. If no structures specified then all are used. chains : bool Split each chain into into a separate atomic structure. ligands : bool Split each connected ligand into a separate atomic structure. connected : bool Split each connected subset of atoms into a separate atomic structure. atoms : list of Atoms Split specified atoms into separate atomic structures. This option can be specified multiple times. ''' if structures is None: from chimerax import atomic structures = atomic.all_atomic_structures(session) if chains is None and not ligands and not connected and atoms is None: chains = True slist = [] olist = [] log = session.logger from chimerax.core.models import Model for m in structures: clist = split_molecule(m, chains, ligands, connected, atoms) if clist: parent = Model(m.name, session) parent.id = m.id for i, c in enumerate(clist): c.id = parent.id + (i+1,) c.position = m.position parent.add(clist) slist.append(m) olist.append(parent) msg = 'Split %s (#%s) into %d models' % (m.name, m.id_string, len(clist)) else: msg = 'Did not split %s, has only one piece' % m.name log.status(msg) log.info(msg) models = session.models models.close(slist) models.add(olist)
def _find_model(session, id, create=False, new_name='group'): if len(id) == 0: return None ml = session.models pl = ml.list(model_id=id) if pl: p = pl[0] elif create: from chimerax.core.models import Model p = Model(new_name, session) p.id = id pp = _find_model(session, id[:-1], True, new_name) ml.add([p], parent=pp) else: p = None return p