| Crates.io | phosph-rs |
| lib.rs | phosph-rs |
| version | 0.4.0 |
| created_at | 2025-10-26 10:28:42.417823+00 |
| updated_at | 2025-10-26 10:28:42.417823+00 |
| description | Simple, pretty, multiplatform molecular viewer for chemists. |
| homepage | |
| repository | https://codeberg.org/crabby/phosph-rs |
| max_upload_size | |
| id | 1901197 |
| size | 303,998 |
phosph-rsphosph-rs is a Rust project to visualize molecular structures in 3D.
3Dmol.js for notebooks, but yeah, idk 'bout this one
phosph-rs aims to be a simple, pretty, and multiplatform molecular viewer for chemists.
(done) Read molecular structures from an .xyz file.
(done) Display the molecular structure in 3D.
(done) Intuitive camera controls.
Export to an image file.
Pretty (i.e. sensible colors, dynamic lighting, etc.)
Ultimately we want to be able to add or remove atoms and bonds, change their colors, etc. This requires a flexible data structure that can be easily manipulated, so it is worth to spend some time on getting this right.
In their most basic form, molecules are frequently represented simply by a list of atoms.
In an .xyz file, each line contains the element symbol and the 3D x, y, and z coordinates of the atom.
To render the molecule, we need to infer the bonds between atoms and also have some visual settings on how to render each element, bond type, etc.
Given the atoms and their positions, we can look up their covalent radii and infer the bonds between them by checking if the distance between two atoms is less than the sum of their covalent radii.
To keep track of this, we will represent the molecule as an undirected graph, where the atoms are the nodes and the bonds are the edges.
Storing the atoms in a simple list will not suffice, as bonds would stored as a tuple of list indices. This is not flexible though, as it doesn't encode the undirectedness of a molecular bond (i.e. a bond from A to B is the same as B to A) and it doesn't allow for easy removal of atoms or bonds. When an atom is removed, all the indices would need to be updated or the become desynced.
The GUI can be implemented with egui.
I'm not sure how to implement bonds.
On the one hand, its an abstract concept of connecting two (or more?) atoms, on the other hand it is a cylinder (or is it?) I need to build somehow and move to its place.
What does the Molecule graph store?
Do I put the entities in as the nodes? I mean, what happens when I delete an entity?
Do I need to deal with lifetimes?
Maybe I am overthinking it.
Maybe I don't need the Molecule right now at all, I can also just have a system to create a bond
without the covalent_radius constraint.
Yeah, I think that should work.
Maybe the atoms could be children of the bond?