Hide and display a specific ligand by adjusting its transparency
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();
Using transparency is an option to do this. The code you posted seems OK at first glance, is it not working for you?
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?
I also encountered the same problem. Is there any more detailed solution?
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 :(