nglviewer / ngl

WebGL protein viewer
http://nglviewer.org/ngl/
MIT License
663 stars 167 forks source link

superpose: ReferenceError: NGL is not defined #170

Closed hainm closed 8 years ago

hainm commented 8 years ago

(I am using code from ngl dev, just pulled)

        superpose: function(cindex0, cindex1, params){
           // superpose two components with given params (not yet)
           var component0 = this.stage.compList[cindex0];
           var component1 = this.stage.compList[cindex1];
           //component0.superpose(component1);
           console.log(component0.superpose);
           //NGL.useWorker = true;
           component0.superpose(component1);
           //NGL.useWorker = false;
        },

In console, I can see the function 'superpose' code but keep getting 'ReferenceError: NGL is not defined'.

Any idea how to fix it? thanks.

arose commented 8 years ago

can you try again, I made some fixes lately and just updated dist/ngl.js

hainm commented 8 years ago

got the same error with the newest commit: eda4864d1688c9d2eef93d16e0d9cb13414b44b1

hainm commented 8 years ago

just clean my cache and your commit works for me. I will double-check.

hainm commented 8 years ago

uhm, try again and still get the same error. Weird.

hainm commented 8 years ago

You can try this branch: https://github.com/arose/nglview/pull/396

arose commented 8 years ago

In console, I can see the function 'superpose' code but keep getting 'ReferenceError: NGL is not defined'.

In the error, can you see the code that throws it originally?

hainm commented 8 years ago

var C = e.getView(new NGL.Selection(r + " and .CA"))

(saw from minimized code)

arose commented 8 years ago

Thanks! Fixed a whole bunch of similar bugs 7d6d3c9e32b08c1d684e41eaec718f71ffbcddaf.

hainm commented 8 years ago

new error in here

Exception in Comm callback TypeError: Cannot read property 'getAtomSet' of undefined(…) TypeError: Cannot read property 'getAtomSet' of undefined

        getAtomSet: function(t, i) {
            e.Debug && Cu.time("StructureView.getAtomSet");
            var r = this.structure.getAtomSet(t);
            return !i && this.atomSet && (r = r.new_intersection(this.atomSet)),
            e.Debug && Cu.timeEnd("StructureView.getAtomSet"),
            r
        },
arose commented 8 years ago

This is odd, it suggests the StructureView has no parent structure?! Can you give some context. How are you calling this. Does the error only occurs with the superpose method?

hainm commented 8 years ago

Can you give some context. How are you calling this

        superpose: function(cindex0, cindex1){
           // superpose two components
           var component0 = this.stage.compList[cindex0];
           var component1 = this.stage.compList[cindex1];
           component0.superpose(component1);
        },
view._remote_call('superpose', target='Widget',
                 args=[0, 1])

Does the error only occurs with the superpose method?

Yes

hainm commented 8 years ago

This is the output from

c = this.stage.compList[0]

for (var i in c){
    console.log(i)
}
name
uuid
visible
signals
stage
viewer
reprList
structure
trajList
selection
structureView
defaultAssembly
constructor
type
initSelection
setSelection
setDefaultAssembly
rebuildRepresentations
rebuildTrajectories
addRepresentation
addTrajectory
removeTrajectory
dispose
centerView
getCenter
superpose
setVisibility
addBufferRepresentation
removeRepresentation
updateRepresentations
clearRepresentations
setStatus
setName
eachRepresentation
__getRepresentationComponent
hainm commented 8 years ago

very weird

If I wrote straight JS script, I can see the superposition. (Try to remove all cache to make sure I am using correct ngl.js file)

%%html

<script>
stage.setParameters({backgroundColor: 'white'})

stage.loadFile("./1crn.pdb", {defaultRepresentation: true})
stage.loadFile("./tz2.single.pdb", {defaultRepresentation: true})
</script>
%%html
<script>

var c0 = stage.compList[0];
var c1 = stage.compList[1];

</script>
%%html
<script>
    console.log(stage.compList)
    console.log(stage.compList[0])

    c0.superpose(c1)
</script>
hainm commented 8 years ago

In JS script mode

NGL.superpose(c0, c1)

TypeError: Object #


has no method 'getView'

BUT

c0.superpose(c1)

OK

hainm commented 8 years ago

LOL, weirder

If I specify

arose commented 8 years ago

You must make sure that both molecules actually have finished loading, looking at your code, this could be the problem.

hainm commented 8 years ago

I only hit enter to run my code if I saw two structures.

arose commented 8 years ago

NGL.superpose(c0, c1)

that is not supposed to work, NGL.superpose expects Structure or StructureView objects.

arose commented 8 years ago

c0.superpose(c1): got error

this should definitely work

arose commented 8 years ago

I just did a new install from this repo and the following works for me:

import nglview
view = nglview.show_pdbid("3pqr")  # load "3pqr" from RCSB PDB and display viewer widget
view
view.add_structure(nglview.PdbIdStructure("1gzm"))
view._remote_call('superpose', target='Widget', args=[0, 1])
hainm commented 8 years ago

indeed. cache is evil. thanks.

arose commented 8 years ago

I am glad it is resolved, I was out of ideas. :-)