Visitar URL original
Ribocode extension by agdturner · Pull Request #1726 · molstar/molstar · GitHub
Skip to content

Ribocode extension - #1726

Open
agdturner wants to merge 32 commits into
molstar:masterfrom
ribocode-slola:master
Open

agdturner wants to merge 32 commits into
molstar:masterfrom
ribocode-slola:master

Conversation

@agdturner

@agdturner agdturner commented Dec 20, 2025 •

Copy link
Copy Markdown
Contributor

Description

Some generally useful geometry for aligning molecules

Actions

  • Added description of changes to the [Unreleased] section of CHANGELOG.md
  • Updated headers of modified files
  • Added my name to package.json's contributors
  • (Optional but encouraged) Improved documentation in docs

@agdturner

Copy link
Copy Markdown
Contributor Author

The repository for Ribocode is: https://github.com/ribocode-slola/ribocode1/
The PWA is linked in the Readme.
I am already in the list of contributors in package.json.

@arose

arose commented Dec 20, 2025

Copy link
Copy Markdown
Member

Did you see src\mol-math\linear-algebra\3d\minimize-rmsd.ts? I think it already offers mathematically 'optimal' alignment of point sets. Also note the recently added src\mol-math\linear-algebra\3d\tm-align.ts for potentially biologically more meaningful alignment.

@agdturner

agdturner commented Dec 21, 2025 •

Copy link
Copy Markdown
Contributor Author

Ah, thanks @arose - no, I had not seen those - there are similarities and it would be good to compare the algorithms and performance on some data... Alignment can be difficult! I found that I could align some molecules better by eye than using the algorithm I implemented. I hard coded a 50 iteration limit for the Newton-Raphson iterative approximation which could be too small...

@dsehnal dsehnal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Before we merge this though, should do some refactoring.

* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
export class QCProt {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @arose pointed out, there is already quaternion-based RMSD minimization code in https://github.com/molstar/molstar/blob/master/src/mol-math/linear-algebra/3d/minimize-rmsd.ts, although the implementation here does seem to better handle edge-cases.

I would prefer we improve the existing code instead of including a duplicate.

Comment thread src/extensions/ribocode/structure.ts Outdated
* @returns A promise that resolves to an object containing arrays of
* x, y, z coordinates and atom types.
*/
export async function getAlignmentData(plugin: PluginUIContext, trajectory: any) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very hacky way of getting the position elements -- generally I would at least get this from the Model which has types data.

Is the purpose of the loadMoleculeFileToViewer only to get the positions? The way this thing is coded seems quite specific to the application you want to use this in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, but you know better what you are doing with Mol* and I am trying to learn how to use it @dsehnal!

The molecule is centralised so that the coordinate origin is at the centre of the molecule (the position of each atom is translated by the average of all the atom positions). If alignment data are provided, then the atoms are also rotated. If the user requests alignment data to be returned, then the centralised atom locations are returned.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's step back a little. The functionality you want is:

  • Load two or more ribosomes
  • Compute their alignment and apply it to the structures
  • Output the translations and matrices to the user

Am I missing something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think that is the gist of it @dsehnal.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then you want to structure your library differently. I would suggest

  • Load all the structures using built-in methods (you don't need the trajectory.ts file you added)
  • Find the superpositions
    • I am having some trouble understanding what alignmentData.type means in relation to selectedAtomTypes in alignDataset, but basically the method should get a selection you want to align and output a transformation matrix
  • Apply TransformStructureConformation based on the transformations to update the visuals
  • To the user, you can either output the transformation matrix or the transformed positions
    • But this would be part of your particular instance of Mol*, not necessarily the extension.

I would again encourage you to have a look at #1723 which achives a lot of what you want (= adding an alternative superposition method)

* @param z Z coordinates to align with
* @return Aligned coordinates as {alignedX, alignedY, alignedZ}
*/
export function alignDataset(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ddelalamo-takeda recently added support for tm-align #1723 which follows the existing patterns for superposing structures (notably the input of Structure.Loci instead of the selectedAtomTypes filtering you have inside the function). Can you follow this pattern here as well?

Due to the usage of big.js, I would still prefer this being a separate extension instead of part of the core library.

* @param coords Array of BigVec3 coordinates.
* @returns Centroid as Vec3
*/
export function computeBigCentroid(coords: Vec3[]): Vec3 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, how big structures to force the use of an arbitrary precision library?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ribosome datasets can have hundreds of thousands of atoms.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong, but the precision of the atom positions themselves isn't very accurate and 15 significant digits still seems quite good.

What is generally the error between using the 64bit floats vs the arbitrary precision computation? And if the different centroid is used in the RMSD calculation, what is the difference then?

Comment thread terq Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra file that should not be here?

@agdturner agdturner Dec 21, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, not sure where that is from. I did not include it intentionally.

Comment thread package.json
"@types/node-fetch": "^2.6.13",
"@types/swagger-ui-dist": "3.30.6",
"argparse": "^2.0.1",
"big.js": "^7.0.1",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I prefer not to include 3rd party dependencies if it could be avoided.

BigJS is MIT and just a single file, which means we could actually just copy-paste it into mol-util/big.ts (and include proper typescript definition). I could help with that if you want.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read that type definitions are included in big.js 7.0.1, but I'm not sure how...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that the Type definitions for Big.js can be added with:
npm install --save-dev @types/big.js

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I don't want to include a dependency on another 3rd party library if it's somewhat easily avoidable.

@dsehnal dsehnal mentioned this pull request Jan 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants