chem_nor 0.5.4
chem_nor: ^0.5.4 copied to clipboard
Dart package that finds relevant chemical compounds using AI(Gemini) and PubChem. Use it to level up your chemistry knowledge and chat with your Ai chemist!
#ChemNOR
Chemical Heuristic Evaluation of Molecules Networking for Optimized Reactivity #
A powerful Dart package that discovers relevant chemical compounds using Google Gemini AI and PubChem β your all-in-one chemistry toolkit.
π Overview #
ChemNOR combines the power of Google Gemini AI with the vast PubChem chemical database to give you:
- π¬ AI-driven compound discovery via SMILES pattern generation
- π¬ Conversational AI Chemist for chemistry Q&A
- π§ͺ Formula parsing, IUPAC naming, and molecular weight calculation
- π NMR, IR, and Mass spectroscopy simulation
- βοΈ Automatic chemical equation balancing
- π‘οΈ GHS safety data retrieval
- πΌοΈ Molecular structure visualization
Note: A Google Cloud API Key is required for AI features.
π Installation #
Add the following to your pubspec.yaml:
dependencies:
chem_nor: ^0.5.4
Then run:
dart pub get
βοΈ Initialization #
Default Model (gemini-2.5-flash) #
import 'package:chem_nor/chem_nor.dart';
final chemNor = ChemNOR(genAiApiKey: 'your-api-key');
Specifying a Model #
final chemNor = ChemNOR(
genAiApiKey: 'your-api-key',
model: GeminiModel.gemini_2_5_pro.apiName,
);
note: use .apiName to get the api name of the model Available models:
| Model | Identifier |
|---|---|
| Gemini 2.5 Flash Lite | GeminiModel.gemini_2_5_flash_lite.apiName |
| Gemini 2.5 Flash | GeminiModel.gemini_2_5_flash.apiName |
| Gemini 2.5 Pro | GeminiModel.gemini_2_5_pro.apiName |
| Gemini 3.0 Flash Preview | GeminiModel.gemini_3_flash_preview.apiName |
| Gemini 3.0 Pro Preview | GeminiModel.gemini_3_pro_preview.apiName |
// Print all available models
print(ChemNOR.availableModels);
𧬠Core Features #
1. π Find Relevant Compounds #
Finds chemical compounds matching an application description using AI-generated SMILES patterns and PubChem lookups.
import 'package:chem_nor/chem_nor.dart';
void main() async {
final chemNor = ChemNOR(genAiApiKey: 'your-api-key');
final results = await chemNor.findListOfCompounds('carboxylic acid compounds');
print(results);
}
π View Text Output
ChemNOR Compound Search Results
Generated at: 2025-02-06 13:55:01
Query SMILES patterns: C(=O)O, O=C(O)O, C(=O)C, C(=O)OC, C(=O)CC
====================================================
CID: 284
Name: formic acid
Molecular Formula: CH2O2
SMILES: C(=O)O
Hydrogen Bond Donor: 1
Hydrogen Bond Acceptor: 2
TPSA: 37.3
Complexity: 10.3
--------------------------------------------
CID: 767
Name: carbonic acid
Molecular Formula: CH2O3
SMILES: C(=O)(O)O
Hydrogen Bond Donor: 2
Hydrogen Bond Acceptor: 3
TPSA: 57.5
Complexity: 26.3
--------------------------------------------
For JSON output, use findListOfCompoundsJSN:
final results = await chemNor.findListOfCompoundsJSN('carboxylic acid compounds');
print(results);
2. π Substructure Search #
Searches PubChem for compounds containing a given SMILES pattern and returns a list of matching compound IDs (CIDs).
final cids = await chemNor.getSubstructureCids('CC');
print(cids); // Output: [6324]
3. π€ AI SMILES Generation #
Uses Gemini AI to suggest relevant SMILES patterns based on a chemical application description.
final smiles = await chemNor.getRelevantSmiles('carboxylic acid compounds');
print(smiles);
// Output: [C(=O)O, CC(=O)O, c1ccccc1C(=O)O, OC(=O)C(=O)O, ...]
4. π Compound Properties #
Fetches detailed compound properties from PubChem using a CID.
final props = await chemNor.getCompoundProperties('248');
print(props);
// Output: {cid: 248, name: carboxymethyl(trimethyl)ammonium, formula: C5H12NO2+, weight: 118.15, ...}
5. π¬ AI Chemist #
Chat with an AI chemist specializing in chemistry topics. Uses Gemini AI with chemistry-focused context.
void main() async {
final chemNor = ChemNOR(genAiApiKey: 'your-api-key');
final response = await chemNor.Chemist(
'Please educate me about carboxymethyl(trimethyl)ammonium'
);
print(response);
}
The
Chemistmethod focuses on chemistry-related questions. Use thechatmethod for general-purpose conversation with optional chat history context.
π§° Additional Modules #
π Formula Parser #
Parses chemical formulas into element maps.
final elements = parseFormula('H2SO4');
print(elements); // Output: {H: 2, S: 1, O: 4}
π·οΈ IUPAC Naming #
Generates IUPAC names from SMILES notation via PubChem.
final name = await generateIupacName('CCO');
print(name); // Output: ethanol
βοΈ Molecular Weight #
Calculates molecular weight from a chemical formula.
final weight = calculateMolecularWeight('H2O');
print('Water molecular weight: $weight g/mol');
// Output: Water molecular weight: 18.01528 g/mol
π‘οΈ Periodic Table #
Access detailed information about any element.
final oxygen = PeriodicTable.getBySymbol('O');
print('Oxygen: atomic number ${oxygen?.atomicNumber}, mass ${oxygen?.atomicMass}');
// Output: Oxygen: atomic number 8, mass 15.999
final metals = PeriodicTable.getByCategory('transition metal');
print('Number of transition metals: ${metals.length}');
// Output: Number of transition metals: 38
βοΈ Reaction Balancer #
Automatically balances chemical equations.
final balanced = ReactionBalancer.balance('H2 + O2 = H2O');
print(balanced); // Output: 2H2 + O2 = 2H2O
π‘οΈ Safety Data (GHS) #
Retrieves GHS chemical safety classifications and hazard codes.
final safetyInfo = await getSafetyData('acetone');
print('Signal word: ${safetyInfo['signal_word']}');
print('Hazard statements: ${safetyInfo['hazard_statements']}');
// Output:
// Signal word: Danger
// Hazard statements: {H225, H319, H336}
π SMILES Parser #
Analyzes SMILES notation to extract structural information.
final structure = parseSmiles('CCO');
print(structure);
// Output: {atomCounts: {C: 2, O: 1}, bondCounts: {single: 2, ...}, rings: 0, ...}
final isValid = isSmilesValid('C1=CC=CC=C1');
print('Is benzene SMILES valid? $isValid'); // Output: true
π‘ Spectroscopy Simulation #
Simulates NMR, IR, and Mass Spectrometry data from molecular structures.
// Proton NMR
final nmrData = await simulateProtonNmr('CCO');
print(nmrData['summary']);
// Output:
// ΒΉH NMR prediction for ethanol:
// Ξ΄ 0.9 ppm (triplet, 3H) - Methyl group (-CHβ)
// Ξ΄ 3.5 ppm (singlet (broad), 1H) - Hydroxyl group (-OH)
// Ξ΄ 3.6 ppm (quartet, 2H) - CHβ adjacent to oxygen
// IR Spectrum
final irData = await simulateIrSpectrum('CCO');
print('IR bands: ${irData['bands'].length}'); // Output: IR bands: 4
πΌοΈ Molecular Visualization #
Generates a PubChem URL to visualize a compound from SMILES.
final url = drawMolecule('CCO');
print(url);
// Output: https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/CCO/PNG
π¬ Complete Example #
Combine all modules for a comprehensive chemical analysis pipeline:
import 'package:chem_nor/chem_nor.dart';
void main() async {
final chemNor = ChemNOR(genAiApiKey: 'your-api-key');
// 1. Find compounds related to a query
final compounds = await chemNor.findListOfCompounds('analgesic compounds');
if (compounds.isNotEmpty) {
final smiles = 'CC(=O)OC1=CC=CC=C1C(=O)O'; // Aspirin SMILES
// 2. Get IUPAC name
final name = await generateIupacName(smiles);
// 3. Calculate molecular weight
final formula = 'C9H8O4';
final weight = calculateMolecularWeight(formula);
// 4. Get GHS safety information
final safety = await getSafetyData('aspirin');
// 5. Simulate NMR spectrum
final nmrData = await simulateProtonNmr(smiles);
// 6. Generate visualization
final visUrl = drawMolecule(smiles);
// 7. Print comprehensive report
print('Compound: $name');
print('Formula: $formula');
print('Molecular Weight: $weight g/mol');
print('Safety Signal: ${safety['signal_word']}');
print('NMR Summary: ${nmrData['summary']}');
print('Visualization: $visUrl');
}
}
π¦ Module Summary #
| Module | Function | Description |
|---|---|---|
| π¬ ChemNOR Core | findListOfCompounds |
AI + PubChem compound search |
| π¬ ChemNOR Core | findListOfCompoundsJSN |
JSON-formatted compound search |
| π¬ ChemNOR Core | getSubstructureCids |
PubChem substructure search |
| π¬ ChemNOR Core | getRelevantSmiles |
AI-generated SMILES suggestions |
| π¬ ChemNOR Core | getCompoundProperties |
PubChem compound property lookup |
| π¬ Chemist | Chemist / chat |
AI chemistry chatbot |
| π Formula Parser | parseFormula |
Element map from formula |
| π·οΈ IUPAC Naming | generateIupacName |
SMILES β IUPAC name |
| βοΈ Molecular Weight | calculateMolecularWeight |
Formula β molecular weight |
| π‘οΈ Periodic Table | PeriodicTable.getBySymbol |
Element data lookup |
| βοΈ Reaction Balancer | ReactionBalancer.balance |
Equation balancing |
| π‘οΈ Safety Data | getSafetyData |
GHS hazard information |
| π SMILES Parser | parseSmiles / isSmilesValid |
SMILES structure analysis |
| π‘ Spectroscopy | simulateProtonNmr / simulateIrSpectrum |
Spectrum simulation |
| πΌοΈ Visualization | drawMolecule |
PubChem structure image URL |
π License #
This project is licensed under the MIT License β see the LICENSE file for details.