Give me a python snippet to calculate the molecular weight of a SMILES string.
- User
Give me a python snippet to calculate the molecular weight of a SMILES string.
Assistant
Here's a Python snippet using RDKit to calculate the molecular weight of a compound from its SMILES string:
pythonfrom rdkit import Chem def calculate_molecular_weight(smiles): try: mol = Chem.MolFromSmiles(smiles) if mol is None: return None return Chem.Descriptors.ExactMolWt(mol) except: return None # Example usage smiles = "CC(=O)OC1=CC=CC=C1C(=O)O" # Aspirin mw = calculate_molecular_weight(smiles) print(f"Molecular Weight: {mw:.2f} g/mol")This code:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.