nglviewer / ngl

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

Why is the effect after superposition not as good as before superposition #1029

Open tang2552 opened 3 months ago

tang2552 commented 3 months ago

before superposition before after superposition after

Previous code `const pdbFile1 = “./data/7KMB.pdb”; const pdbFile2 = ”./data/7KMS.pdb“;

function initNGL() { // Create a stage const stage = new NGL.Stage("viewport");

// Load protein structure files (PDB or MMCIF)
stage.loadFile(pdbFile1).then(function (component1) {
    stage.loadFile(pdbFile2).then(function (component2) {
        // Add components to the stage
        stage.addComponent(component1);
        stage.addComponent(component2);

        console.log("Components added to stage");

        // Representations (e.g., cartoon representation)
        component1.addRepresentation("cartoon", {color: "red"});
        component2.addRepresentation("cartoon", {color: "blue"});

        console.log("Representations added");

        // Align structures (you may have to perform alignment before loading)
        // Make sure alignView is supported in your NGL version
        if (typeof stage.alignView === "function") {
            stage.alignView();
            console.log("Aligning view");
        } else {
            console.warn("alignView method is not available");
        }
        stage.setParameters({ backgroundColor: "white" });

        // Auto view
        stage.autoView();
    }).catch(function(error) {
        console.error("Error loading file 2:", error);
    });
}).catch(function(error) {
    console.error("Error loading file 1:", error);
});

}`

The following code refers to the following URL https://github.com/nglviewer/ngl/blob/master/examples/scripts/test/superposition.js

Obviously, the effect after superpose is not as good as before.

I'd appreciate it if someone could solve my problem. Thanks!

ppillot commented 3 months ago

This code looks strange to me: you are referring to this link https://github.com/nglviewer/ngl/blob/master/examples/scripts/test/superposition.js but none of the code pasted is looking alike, in particular stage.alignView() which is not a method existing on the stage object (it exists on the ViewerControls class, but that's not how superposition are done in the examples; all examples are using NGL.superpose(...) for performing superpositions). To me, this looks like code that has been hallucinated by an AI.

Regarding the issue you are reporting, I have no experience with using the superposition method, but my recommandation would be to use the code from the following example, https://github.com/nglviewer/ngl/blob/master/examples/scripts/test/alignment2.js where the chains to be aligned are specified (:A). In the case of the 2 structures you want to superpose, I suppose that getting good results would require to specify the correct pair of chains for the alignment, otherwise the combinatorial is too random.