molstar / molstar

A comprehensive macromolecular library
https://molstar.org
MIT License
608 stars 142 forks source link

Select a chain #1150

Open nataliarosa9 opened 1 month ago

nataliarosa9 commented 1 month ago

I'm trying to select a chain in the query using Mol-script language. I can do it when the query is like this:

Script.getStructureSelection(Q => Q.struct.generator.atomGroups({
    "chain-test": Q.core.rel.eq([MolScriptBuilder.struct.atomProperty.macromolecular.auth_asym_id(), 'A']),
    'residue-test': Q.core.set.has([Q.set(positions), Q.ammp('auth_seq_id')]),
    'group-by': Q.struct.atomProperty.macromolecular.residueKey(),
}), dta);

But I need to figure out how to do it in this scenario.

    // Set script language
        const language = 'mol-script';

        // Create params object
        const params = {
            layers: []
        };

        // Add layers to params object
        for (let i = 0; i < positions.length; i++) {
            const start = positions[i];
            const stop = positions[i];
            params.layers.push({
                script: Script(
                     `(sel.atom.res (in-range atom.resno ${start} ${stop}))`,
                    language
                ),
                color: Color(0xf0e68c),
                clear: false
            });
        }
dsehnal commented 2 weeks ago

What are you trying to achieve?

nataliarosa9 commented 2 weeks ago

I want to repaint a specific section of the structure on a particular chain. ...

        // Get polymer representation
        const cartoon = structure.representation.representations.polymer;

         // Create and apply custom representation
        const reprParamsStructureResetColor = createStructureRepresentationParams(plugin, undefined, {
          type: 'cartoon',
          color: 'uniform',
          colorParams: { value: ColorNames.gray }
        });

        const update = await plugin
        .build()
        .to(cartoon)
        .update(reprParamsStructureResetColor);

        // Set script language
        const language = 'mol-script';

        // Create params object
        const params = {
            layers: []
        };

        // Add layers to params object
        for (let i = 0; i < positions.length; i++) {
            const start = positions[i];
            const stop = positions[i];
            const chain = 'B';
            params.layers.push({
                script: Script(
                     `(sel.atom.res (in-range atom.resno ${start} ${stop}))`,
                    language
                ),
                color: Color(0xf0e68c),
                clear: false
            });
        }

        // Apply yellow color
        const update2 = plugin.build();
        update
              .to(cartoon)
              .apply(StateTransforms.Representation.OverpaintStructureRepresentation3DFromScript, params);

        await update.commit();
        await update2.commit();

...

immagine