ngl icon indicating copy to clipboard operation
ngl copied to clipboard

comp.addRepresentation does not respect defaultAssembly param?

Open hainm opened this issue 6 years ago • 2 comments

hi,

This issue is originally from nglview (https://github.com/arose/nglview/issues/802#issuecomment-492709317).

I am giving brief information (let me know if you need further information or code). Basically I want to set repr from a given params ("assembly": "default", "defaultAssembly": "BU1") via component.addRepresentation:

{"type": "cartoon", "params": {"lazy": false, "visible": true, "quality": "medium", "aspectRatio": 5, "subdiv": 6, "radialSegments": 10, "tension": null, "capped": true, "smoothSheet": false, "radiusType": "sstruc", "radiusData": {}, "radiusSize": 1, "radiusScale": 0.7, "assembly": "default", "defaultAssembly": "BU1", "clipNear": 0, "clipRadius": 0, "clipCenter": {"x": 0, "y": 0, "z": 0}, "flatShaded": false, "opacity": 1, "depthWrite": true, "side": "double", "wireframe": false, "colorScheme": "chainname", "colorScale": "RdYlBu", "colorReverse": false, "colorValue": 9474192, "colorMode": "hcl", "roughness": 0.4, "metalness": 0, "diffuse": 16777215, "diffuseInterior": false, "useInteriorColor": true, "interiorColor": 2236962, "interiorDarkening": 0, "matrix": {"elements": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]}, "disablePicking": false, "sele": "all"}}

However, the output defaultAssembly is changed, it is set to empty string. Is this intention? thanks and cheers.

hainm avatar May 15 '19 18:05 hainm

defaultAssembly is a hidden/internal parameter you don't set it directly but via StructureComponent params or .setDefaultAssembly

arose avatar May 15 '19 22:05 arose

thanks for the explanation. It's kind of inconvenient for nglview's serialization in this case though.

Saying

params = repr.repr.getParameters();
[delete all old representations in `repr`]
repr.setParameters(params) // can not restore the previous representations.

Here is the nglview's code https://github.com/arose/nglview/blob/f45da9c8e1d63af879a5903d38843a49d42d14e8/js/src/widget_ngl.js#L470-L485

    _set_representation_from_backend: function(compList){
        if (compList.length > 0){
            var ngl_repr_dict = this.model.get('_ngl_repr_dict');
            for (var index in ngl_repr_dict){
                var comp = compList[index];
                comp.removeAllRepresentations();
                var reprlist = ngl_repr_dict[index];
                for (var j in reprlist){
                    var repr = reprlist[j];
                    if (repr){
                        comp.addRepresentation(repr.type, repr.params);
                    }
                }
            }
        }
    },

hainm avatar May 15 '19 22:05 hainm