Opened 7 years ago
Closed 7 years ago
#1515 closed enhancement (fixed)
Make StructureArg more flexible
| Reported by: | Tristan Croll | Owned by: | Tom Goddard |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | Command Line | Version: | |
| Keywords: | Cc: | Elaine Meng | |
| Blocked By: | Blocking: | ||
| Notify when closed: | Platform: | all | |
| Project: | ChimeraX |
Description
A minor thing, but I'd like to propose the below modification to StructureArg, allowing it to succeed if (and only if) exactly one model in the specified model's subtree (including the specified model itself) is a Structure. This would be useful for the Clipper plugin, where upon initialisation the atomic model is moved under a top-level "Data Manager" Model containing all the handlers for atomic symmetry, crystallographic maps etc. Making this change would allow adding extra crystallographic maps via e.g.
open 3io0-sf.mtz structureModel #1
rather than having to search through the Model Panel to work out that the atomic model is now #1.3.
class StructureArg(ModelArg):
"""Parse command structure specifier"""
name = "a structure specifier"
@classmethod
def parse(cls, text, session):
m, text, rest = super().parse(text, session)
from . import Structure
models = [cm for cm in m.all_models() if isinstance(cm, Structure)]
if len(models) != 1:
if not isinstance(m, Structure):
raise AnnotationError('Model spec must contain a single Structure')
return models[0], text, rest
I note that the proposed error-handling code is wrong -- it shouldn't have the second 'if' statement. Also, StructuresArg should probably be similarly modified.