A high-performance, open-source 3D and 2D chemical structure visualizer built with Next.js 15, Three.js, and the PubChem PUG REST API.
3d-mole (github.com/anshk1234/3D-Mole) provides researchers, chemists, students, and educators with a minimalist, ultra-fast interface for rendering, inspecting, and analyzing molecular structures in real-time. By fetching 3D SDF conformers and high-resolution 2D skeletal structures directly from PubChem, 3d-mole delivers interactive visualization with zero server latency.
- Multiple Display Modes: Render molecules in Ball & Stick, Spacefilling (VDW), Sticks, or Wireframe representations.
-
Raycasting & Atom Selection: Click any atom in 3D space to inspect its element, index, and 3D coordinates
$(x, y, z)$ . -
Distance Measurement: Select two atoms sequentially to calculate exact interatomic Euclidean distance in Angstroms (
$\text{\AA}$ ). - Dynamic Lighting & Controls: Full camera controls (orbit, pan, zoom), toggleable smooth auto-rotation, camera view reset, and high-res PNG snapshot exporter.
- Preserved Canvas Lifecycle: Smooth theme toggling without resetting or flickering 3D webgl contexts.
- Vector Skeletal Graphics: Clean PubChem 2D diagrams featuring stereobonds, double/triple bonds, and heteroatom color coding.
-
Interactive Canvas: Smooth zoom controls (
$60%$ to$220%$ ) and high-resolution PNG download.
-
Key Metrics Grid: Instant calculation/display for Molecular Weight (
$\text{g/mol}$ ), Topological Polar Surface Area ($\text{TPSA}$ in$\text{\AA}^2$ ), Lipophilicity ($\text{LogP}$ /$\text{XLogP3}$ ), and Hydrogen Bond Donor/Acceptor counts. - Structural Identifiers: Copyable IUPAC Name, Canonical SMILES, and InChIKey, alongside direct links to PubChem compound entries.
- OLED Black / Minimalist Theme: Obsidian dark mode
#000000paired with crisp typography and subtle border accents. - Light Mode Support: Clean, high-contrast light mode for printing or daylight viewing.
- Responsive Layout: Seamless navigation across split side-by-side mode, dedicated 3D mode, and 2D mode.
- Framework: Next.js 15 (App Router)
- Language: TypeScript
- 3D Graphics Engine: Three.js
- Styling: Tailwind CSS v4
- Icons: Lucide React
- Data Source: PubChem PUG REST API
Ensure you have the following installed on your system:
- Node.js:
v18.0.0or higher - npm:
v9.0.0or higher (orpnpm/yarn)
-
Clone the repository:
git clone https://github.com/anshk1234/3D-Mole.git cd 3D-Mole -
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
Open in browser: Navigate to
http://localhost:3000to access the application.
To build the application for production:
# Create optimized production build
npm run build
# Start production server
npm run startSince 3d-mole is a client-rendered React/Next.js application leveraging external public APIs, it can be deployed with zero backend configuration on platform hosts such as Vercel, Netlify, or Docker/Cloud Run.
3d-mole/
├── app/
│ ├── globals.css # Tailwind CSS imports & global styles
│ ├── layout.tsx # Root application layout
│ └── page.tsx # Main application visualizer view
├── components/
│ ├── MoleculeHeader.tsx # Search bar, presets, view switchers, theme toggle
│ ├── Molecule3DViewer.tsx # Three.js 3D conformer canvas & controls
│ ├── Normal2DViewer.tsx # 2D structure viewer with zoom & export
│ └── MoleculeDetails.tsx # Property metrics grid & chemical table
├── lib/
│ └── pubchem.ts # PubChem REST API fetching & SDF parser
├── types/
│ └── chemistry.ts # TypeScript definitions for compounds & atoms
├── package.json
└── README.md
- Search Query Resolution: Resolves user queries (e.g.
caffeine,C8H10N4O2,CID 2519) to PubChem Compound Identifiers (CID) via:https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/{query}/cids/JSON - 2D & Property Data: Fetches structural properties and standard 2D vector diagrams via PubChem's JSON and SVG endpoints.
- 3D SDF Conformer Parser: Fetches 3D atomic coordinates in Structure-Data File (
.sdf) format via:https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/{cid}/SDF?record_type=3d - Three.js Scene Builder: Parses the SDF block into atomic nodes (element, radius, CPK color, coordinates) and bond connectors, rendering spheres and cylinders in a 3D webgl scene.
Contributions are welcome! Please feel free to submit a Pull Request or open an Issue for bug reports or feature requests.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.