IMO, there was simply no demand so far for loading SDF molecule definitions, especially since there is a PDBLoader
around. Looking at the SDF/Mol File Format Specification, a loader shouldn’t be that complicated to implement. However, I would suggest a different approach like with PDBLoader
.
It might make more sense to write a three.js
independent library that takes SDF text content as an input and returns a JSON representation. We could then add an external three.js example that imports the lib, parse a loaded SDF with it and then visualizes the result with a CSS renderer or with WebGL/WebGPU.
Unlike other loaders for OBJ, FBX or glTF, the visualization of molecule data is quite application specific. So instead of writing a SDFLoader
that returns mesh definitions, I would just focus on JSON and let the application do anything else.
The JSON could have the following structure:
{
"molecules": [
{
"name": "Molecule 1 Name (from header if available, or generate one)",
"atoms": [
{
"id": 1,
"element": "C",
"x": 0.0,
"y": 0.0,
"z": 0.0,
"charge": 0
},
{
"id": 2,
"element": "O",
"x": 1.2,
"y": 0.0,
"z": 0.0,
"charge": -1
}
// ... more atoms
],
"bonds": [
{
"from_atom": 1,
"to_atom": 2,
"type": 1, // 1 for single, 2 for double, etc.
"stereo": 0
},
// ... more bonds
],
"properties": {
"logP": 2.5,
"ExactMass": 123.45,
"Source": "Some_Database"
// ... other properties from the SDF/MOL file
}
},
// ... more molecules if it's an SDF file
]
}