molstar icon indicating copy to clipboard operation
molstar copied to clipboard

Hide and display a specific ligand by adjusting its transparency

Open nataliarosa9 opened this issue 1 year ago • 4 comments

How can I hide all ligands and show a specific one using transparency? I want to allow the user to visualize just a particular ligand that they select from the option list.

        const cartoon = structure.representation.representations.polymer;

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

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

       params.layers.push({
                script: Script(
                     `(sel.atom.atom-groups
                         :residue-test (set.has (set NTN) atom.auth_comp_id)
                      )`,
                    language
                ),
                value: 0.1
        });

        // Apply transparency color
        const update = plugin.build();
        update
              .to(cartoon)
              .apply(StateTransforms.Representation.TransparencyStructureRepresentation3DFromScript , params);

        await update.commit();

nataliarosa9 avatar Nov 06 '24 14:11 nataliarosa9

Using transparency is an option to do this. The code you posted seems OK at first glance, is it not working for you?

arose avatar Nov 10 '24 17:11 arose

It’s not working for me. I also tried it, but it did not work either.

const ligand = Script.getStructureSelection(Q => Q.struct.generator.atomGroups({
                    'residue-test': MS.core.rel.eq([MS.struct.atomProperty.macromolecular.label_comp_id(), "MOH"]),
                  'group-by': Q.struct.atomProperty.macromolecular.residueKey(),}), dta);

const loci = StructureSelection.toLociWithSourceUnits(ligand);

await setSubtreeVisibility(plugin.state.data, loci, true);

Besides, how could I hide all the ligands completely?

nataliarosa9 avatar Nov 11 '24 08:11 nataliarosa9

I also encountered the same problem. Is there any more detailed solution?

luckyxutao avatar Nov 20 '24 09:11 luckyxutao

Same problem here! I also tried this :

const trajectory = await plugin.builders.structure.parseTrajectory(data, 'sdf');
const hierarchy = await plugin.builders.structure.hierarchy.applyPreset(trajectory, 'default');

 if (hierarchy) {
    await setSubtreeVisibility(plugin.state.data, hierarchy?.representation, false);
    await setSubtreeVisibility(plugin.state.data, hierarchy?.structure.ref, false);
    await setSubtreeVisibility(plugin.state.data, hierarchy?.model.ref, false);
  }

None of these calls did anything :(

BrannJoly avatar Nov 23 '24 13:11 BrannJoly