Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#4748 closed enhancement (not a bug)

execute command when models opened

Reported by: olibclarke@… Owned by: pett
Priority: moderate Milestone:
Component: General Controls Version:
Keywords: Cc: chimera-programmers, Elaine Meng, tony.schaefer@…, danielgurnon@…
Blocked By: Blocking:
Notify when closed: Platform: all
Project: ChimeraX

Description

ChimeraX could have a "New Models" settings category, with subsections for various model types, where you could specify commands to run when models of that type were opened.

Change History (7)

comment:1 by pett, 4 years ago

Summary: exexute command when models openedexecute command when models opened

in reply to:  2 ; comment:2 by Tony Schaefer, 4 years ago

SEQCROW's code for this is in the "filereader manager". FileReader is the AaronTools class for parsing files. This manager primarily stores the info parsed from the files SEQCROW opens (normal vibrational modes, energy, etc.). I'll probably move this info to a custom model attribute in the future, and the methods for running commands when models are added can be set up during bundle initialization instead of inside a ProviderManager. The code is here:
https://github.com/QChASM/SEQCROW/blob/master/src/managers/filereader_manager.py

Executing commands when a file is opened was very much modeled after the ChimeraX startup commands.

Relevant lines:
in __init__,
```
session.triggers.add_handler(ADD_MODELS, self.apply_preset)
```


```
​def apply_preset(self, trigger_name, models):
    """if a graphical preset is set in SEQCROW settings, apply that preset to models"""
    for model in models:
        if model in self.models:
            if model.session.ui.is_gui:
                apply_seqcrow_preset(model)

        apply_non_seqcrow_preset(model)
```

```

fmt_only = re.compile("(\S*):(.*)")

def apply_non_seqcrow_preset(model):
    preset = model.session.seqcrow_settings.settings.NON_SEQCROW_IO_PRESET
    atomspec = model.atomspec
    for line in preset:
        cmd = line.replace("<model>", atomspec)
        fmt = fmt_only.match(cmd)
        if fmt is not None and hasattr(model, "filename") and isinstance(model.filename, str):
            file_types = fmt.group(1).split(",")
            root, ext = path.splitext(model.filename)
            ext = ext.strip(".")
            if any(ext.lower() == e.lower() or model.name.lower().startswith("%s:" % e.lower()) for e in file_types):
                run(model.session, fmt.group(2).strip())

        elif fmt is not None:
            file_types = fmt.group(1).split(",")
            root, ext = path.splitext(model.name)
            ext = ext.strip(".")
            if any(ext.lower() == e.lower() or model.name.lower().startswith("%s:" % e.lower()) for e in file_types):
                run(model.session, fmt.group(2).strip())

        else:
            run(model.session, cmd)

```

seqcrow_settings.settings.NON_SEQCROW_IO_PRESET is a StringsOption. Each string looks something like `prefix1,prefix2: command <model> options`. There's three(-ish) cases that can cause a command to be run:

  *   model has a filename attribute and the extension from the filename is in the command prefix or the model's name starts with something in the command prefix; checking the model name prefix works with things like smiles:CC=O, though I don't think filename is set for smiles
  *   the model's name ends with the extension or the model's name starts with something in the command prefix
  *   there is no command prefix - these are run for all models

Of course, I would check the opened_as attribute instead of filename going forward.

Originally, I just snuck in the ability to apply one of SEQCROW's presets to a model SEQCROW opened, as I was always applying a preset after every structure I opened (a lot of the time I'd misclick the wrong preset/menu, too). I figured someone else might want to apply their own preset when they open other files. Someone has asked about this sort of on the mailing list before (https://plato.cgl.ucsf.edu/pipermail/chimerax-users/2020-October/001584.html). However, SEQCROW's presets applying to just one model works because of how they are written - they can take a list of models as an argument. Other people's presets wouldn't necessarily work this way, so I settled on a list of commands for a particular file extension or name prefix.

I think what's in SEQCROW right now works in a lot of cases. It's a bit more granular than looking at the model type, and I'm guessing the filetypes people use remains consistent from day to day. For this type of feature, I can imagine options ranging in complexity from running commands when a model of a particular type is opened, to intricate rules that can be interpreted as either ChimeraX commands or Python code based on the type of model, its file type, file name, etc.

If you want to add this to ChimeraX, feel free to borrow stuff from SEQCROW. This is one feature that doesn't really fit in with the rest of the bundle, and I think it would be useful to some people who would not use any of SEQCROW's other utilities.

Tony
________________________________
From: ChimeraX <ChimeraX-bugs-admin@cgl.ucsf.edu>
Sent: Tuesday, June 8, 2021 6:20 PM
Cc: chimera-programmers@cgl.ucsf.edu <chimera-programmers@cgl.ucsf.edu>; meng@cgl.ucsf.edu <meng@cgl.ucsf.edu>; olibclarke@gmail.com <olibclarke@gmail.com>; pett@cgl.ucsf.edu <pett@cgl.ucsf.edu>; Anthony James Schaefer <tony.schaefer@uga.edu>
Subject: [ChimeraX] #4748: exexute command when models opened

[EXTERNAL SENDER - PROCEED CAUTIOUSLY]


#4748: exexute command when models opened
------------------------------+-------------------------------------
 Reporter:  olibclarke@…      |               Owner:  Eric Pettersen
     Type:  enhancement       |              Status:  assigned
 Priority:  moderate          |           Milestone:
Component:  General Controls  |             Version:
 Keywords:                    |          Blocked By:
 Blocking:                    |  Notify when closed:
 Platform:  all               |             Project:  ChimeraX
------------------------------+-------------------------------------
 ChimeraX could have a "New Models" settings category, with subsections for
 various model types, where you could specify commands to run when models
 of that type were opened.

--
Ticket URL: <https://plato.cgl.ucsf.edu/trac/ChimeraX/ticket/4748>
ChimeraX <http://www.rbvi.ucsf.edu/chimerax/>
ChimeraX Issue Tracker

comment:3 by pett, 4 years ago

Thanks for all this information Tony! It will be helpful when I have the time to implement this.

--Eric

comment:4 by pett, 3 years ago

Cc: danielgurnon@… added

comment:5 by pett, 3 years ago

Additional suggestion from T.G.:

It might be nice if ChimeraX had a preference settings that made it not automatically choose a lighting mode when the first model is opened.

comment:6 by Elaine Meng, 3 years ago

Elaine:

Currently the lighting adjustment upon model opening is part of autostyling, which can be avoided with the "autoStyle false" option of the "open" command.
<https://rbvi.ucsf.edu/chimerax/docs/user/commands/open.html#options>

However, autostyling includes a lot of other mostly helpful things, so you probably wouldn't want to use that option. For example, without autostyling, every atomic structure opens as white spheres.
<https://rbvi.ucsf.edu/chimerax/docs/user/autostyle.html>

It wouldn't be practical to have a preference for every single aspect of autostyling, but perhaps there could be a middle ground with some checkbox options for commonly adjusted things like lighting in addition to a box to enter custom commands for model opening to meet more specific needs. Maybe a "New Structures" or "New Models" section of Preferences analogous to the "New Molecule" category that Chimera had.

comment:7 by pett, 3 years ago

Resolution: not a bug
Status: assignedclosed

It seems that Tony's OpenCommands bundle obviates the need for this.

Last edited 3 years ago by pett (previous) (diff)
Note: See TracTickets for help on using tickets.