Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ InputForm → identifierLookup → Local DB → PubChem API → moleculeParser
- **Confidence Scoring**: Quality assessment based on data completeness

#### **2. Molecular Structure Parser (`moleculeParser.ts`)**
- **SMILES Parser**: Pattern matching for common molecular structures
- **3D Coordinate Generation**: Hand-crafted coordinates for accurate visualization
- **Fallback System**: Multiple parsing strategies for unknown compounds
- **Structure Library**: 70+ pre-defined molecular structures
- **PubChem-Backed Parsing**: Resolves identifiers to PubChem CIDs, then loads real structure records
- **3D-First Coordinates**: Uses PubChem 3D conformers when available, with 2D coordinate fallback
- **Cross-Identifier Resolution**: Supports SMILES, InChI, IUPAC names, CAS numbers, and more through CID lookup
- **Explicit Failure Behavior**: Throws parse errors instead of silently substituting an unrelated molecule

#### **3. 3D Rendering Engine (`Molecule3DComponent.tsx`)**
- **Atomic Representation**: Spheres with CPK coloring and van der Waals radii
Expand Down Expand Up @@ -145,11 +145,10 @@ npm run preview

## 🎯 Current Capabilities

### **Molecule Library** (70+ Structures)
- **Simple Molecules**: Water, methane, ethanol, benzene
- **Pharmaceuticals**: Caffeine, aspirin, glucose
- **Organic Compounds**: Alkanes, alkenes, alcohols, acids
- **Complex Structures**: Purine derivatives, sugar molecules
### **Structure Coverage**
- **Database-Driven**: Renders any molecule that PubChem can resolve with coordinate data
- **Large Coverage**: Handles a far broader set of molecules than fixed hand-coded tables
- **Offline Safety Net**: Keeps a small built-in fallback set for common molecules when network lookup fails

### **Database Integration**
- **Local Database**: 50+ common compounds for instant lookup
Expand All @@ -160,15 +159,11 @@ npm run preview
## ⚠️ Current Issues & Limitations

### **Known Issues**
1. **Limited SMILES Parser**: Only supports ~20 common SMILES patterns
- Complex molecules default to fallback structures
- Stereochemistry information is not preserved
1. **Network Dependency**: External structure retrieval requires PubChem availability
- Some identifiers may resolve to compounds that do not have coordinate records
- Offline fallback intentionally covers only common molecules

2. **Static 3D Coordinates**: Most structures use hand-crafted coordinates
- No automatic 3D structure generation from SMILES
- Some molecules may have suboptimal geometries

3. **API Rate Limiting**: No rate limiting implemented for external APIs
2. **API Rate Limiting**: No rate limiting implemented for external APIs
- Potential for hitting PubChem/NCI rate limits
- No retry strategies for failed requests

Expand All @@ -189,8 +184,8 @@ npm run preview
## 🚧 Future Enhancements

### **High Priority**
- [ ] **Advanced SMILES Parser**: Implement comprehensive SMILES parsing library
- [ ] **Automatic 3D Generation**: Integrate RDKit or similar for structure generation
- [ ] **Local Structure Generation**: Add openchemlib or RDKit-JS for fully offline parsing/generation
- [ ] **Coordinate Robustness**: Add alternate conformer sources when PubChem lacks 3D records
- [ ] **Search History**: Local storage for recently viewed molecules
- [ ] **Export Features**: PNG/SVG export, 3D model download
- [ ] **Performance Optimization**: Level-of-detail rendering for large molecules
Expand Down
16 changes: 13 additions & 3 deletions src/utils/identifierLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,13 @@
}

// Enhanced local lookup for common compounds (expanded database)
export function getLocalIdentifiers(

Check failure on line 569 in src/utils/identifierLookup.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=djleamen_modelcules&issues=AZ7c-b1WP8sb1unwQ7eq&open=AZ7c-b1WP8sb1unwQ7eq&pullRequest=37
sourceType: keyof ChemicalIdentifiers,
sourceValue: string
): Partial<ChemicalIdentifiers> | null {
const lowerValue = sourceValue.toLowerCase().trim();
const trimmedValue = sourceValue.trim();
const lowerValue = trimmedValue.toLowerCase();
const lookupValue = sourceType === 'smiles' ? trimmedValue : lowerValue;

// Comprehensive database of common compounds
const commonCompounds: { [key: string]: Partial<ChemicalIdentifiers> } = {
Expand Down Expand Up @@ -1080,15 +1082,23 @@
};

// Try direct lookup first
const compound = commonCompounds[lowerValue];
const compound = commonCompounds[lookupValue];
if (compound) {
return compound;
}

// Try to find by any matching identifier field
for (const [, identifiers] of Object.entries(commonCompounds)) {
for (const [idType, idValue] of Object.entries(identifiers)) {
if (idType === sourceType && idValue?.toLowerCase() === lowerValue) {
if (idType !== sourceType) {
continue;
}

if (sourceType === 'smiles') {
if (idValue?.trim() === trimmedValue) {
return identifiers;
}
} else if (idValue?.toLowerCase() === lowerValue) {
return identifiers;
}
}
Expand Down
Loading
Loading