﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	blockedby	blocking	notify_on_close	platform	project
683	atomspec_has_atoms() is inconsistently applied.	Tristan Croll	Tom Goddard	"Context: I'm sub-classing AtomicStructure to provide a visualisation of atom positional restraints, with Pseudobonds between true atom and target. I need to take control over visualisation of atoms for this object away from the main UI (that is, make its atoms invisible to AtomSpec).

AtomicStructure has the methods atomspec_has_atoms() and atomspec_atoms() which appear to be designed for this purpose, but they're a little inconsistently applied at the moment. If my subclass of AtomicStructure looks like:


{{{
class PositionRestraintIndicator(AtomicStructure):
    '''
    For each position restraint, we want a neat way to display its target
    position with a bond back to the atom itself. Redrawing needs to be
    fast, since at times there will be many restraints in play at once.
    The simplest way to accomplish this is to work with the pre-existing
    infrastructure for fast handling of atoms and bonds, and build the 
    targets as fake Atoms. This allows us to use the existing Pseudobonds
    functionality to draw the bonds between atoms and their targets, giving
    us a lot of functionality for free. However, it does mean we need to
    subclass AtomicStructure, since we need to take all control over 
    visualisation away from the main ChimeraX interface.
    '''
    
    def atomspec_has_atoms(self):
        return False
        
    def atomspec_atoms(self):
        return None

}}}

... then the atoms within will be ignored by the command-line interface, sure enough - but still treated as ''bona fide'' atoms by everything else. So, for example, if I type:


{{{
show selAtoms
}}}

at the cli with nothing selected, the atoms will still be shown. If I select some with the mouse, then:


{{{
from chimerax.core.atomic import selected_atoms
sel = selected atoms(session)
}}}

... includes these atoms in the returned array, etc.. I think it would be very valuable if atomspec_has_atoms() were respected across the board, to provide for some much more flexible use of AtomicStructure. The changes I've made so far seem to work without breaking anything:

chimerax.core.objects:

{{{
line 61
    def invert(self, session, models):
        from .atomic import Structure, Atoms, concatenate
        matoms = []
        from .orderedset import OrderedSet
        imodels = OrderedSet()
        for m in models:
            if isinstance(m, Structure):
<                matoms.append(m.atoms) 
>                if m.atomspec_has_atoms():
>                    matoms.append(m.atomspec_atoms())
            elif m not in self._models:
                imodels.add(m)
        iatoms = concatenate(matoms, Atoms, remove_duplicates=True) - self.atoms
        imodels.update(iatoms.unique_structures)
        self._atoms = [iatoms]
        self._cached_atoms = iatoms
        self._models = imodels

}}}

chimerax.core.structure:

{{{
line 1637:
    def selected_items(self, itype):
        if itype == 'atoms':
<            atoms = self.atoms
>            atoms = self.atomspec_atoms()
<            if atoms.num_selected > 0:
>             if atoms is not None and atoms.num_selected > 0:
                return [atoms.filter(atoms.selected)]
        return []



line 2543:
def structure_atoms(structures):
    '''Return all atoms in specified atomic structures as an :class:`.Atoms` collection.'''
    from .molarray import concatenate, Atoms
<    atoms = concatenate([m.atoms for m in structures], Atoms)
>    atoms = concatenate([m.atomspec_atoms() for m in structures if m.atomspec_has_atoms()], Atoms)
    return atoms

}}}

With the above changes, a PositionRestraintIndicator model can still have its atoms individually shown/hidden via standard scripting, e.g.:

{{{
m.atoms.displays = True
}}}

... but is otherwise ignored by any atom-directed commands from the interface, which is what I need. I can't see any other way to achieve this without a **lot** more messing around.
"	defect	closed	major		Depiction		fixed						all	ChimeraX
