molecular-properties-calculation

$npx mdskill add InternScience/scp/molecular-properties-calculation

Calculates molecular properties from SMILES strings

  • Solves the task of deriving molecular weight, formula, atom counts, and exact mass from SMILES
  • Uses FastMCP library for communication with a molecular calculation server
  • Processes input SMILES strings to extract chemical structure data
  • Returns calculated properties in a structured format to the user or agent

SKILL.md

.github/skills/molecular-properties-calculationView on GitHub ↗
---
name: molecular-properties-calculation
description: Calculate basic molecular properties from SMILES including molecular weight, formula, atom counts, and exact mass.
license: MIT license
metadata:
    skill-author: PJLab
---

# Molecular Properties Calculation

## Usage

### 1. MCP Server Definition

```python
import asyncio
import json
from fastmcp import Client
from fastmcp.client.transports import StreamableHttpTransport

class ChemicalToolsClient:
    """Chemical Tools MCP Client using FastMCP"""

    def __init__(self, server_url: str, headers: dict = None):
        self.server_url = server_url
        self.headers = headers or {}
        self.client = None

    async def connect(self):
        """Establish connection and initialize session"""
        print(f"Connecting to: {self.server_url}")
        try:
            transport = StreamableHttpTransport(
                url=self.server_url,
                headers=self.headers
            )

            self.client = Client(transport)
            await self.client.__aenter__()

            print(f"✓ connect success")
            return True

        except Exception as e:
            print(f"✗ connect failure: {e}")
            import traceback
            traceback.print_exc()
            return False

    async def disconnect(self):
        """Disconnect from server"""
        try:
            if self.client:
                await self.client.__aexit__(None, None, None)
            print("✓ already disconnect")
        except Exception as e:
            print(f"✗ disconnect error: {e}")

    def parse_result(self, result):
        """Parse MCP tool call result"""
        try:
            if hasattr(result, 'content') and result.content:
                content = result.content[0]
                if hasattr(content, 'text'):
                    try:
                        return json.loads(content.text)
                    except:
                        return content.text
            return str(result)
        except Exception as e:
            return {"error": f"parse error: {e}", "raw": str(result)}
```

### 2. Molecular Properties Calculation Workflow

This workflow calculates fundamental molecular properties from SMILES strings, useful for drug discovery, chemical analysis, and computational chemistry.

**Workflow Steps:**

1. **Calculate Molecular Weight** - Compute average molecular weight
2. **Calculate Molecular Formula** - Determine elemental composition
3. **Calculate Exact Molecular Weight** - Compute monoisotopic mass
4. **Count Atoms** - Determine total and heavy atom counts

**Implementation:**

```python
## Initialize client
HEADERS = {"SCP-HUB-API-KEY": "<your-api-key>"}

client = ChemicalToolsClient(
    "https://scp.intern-ai.org.cn/api/v1/mcp/31/SciToolAgent-Chem",
    HEADERS
)

if not await client.connect():
    print("connection failed")
    exit()

## Input: SMILES string to analyze
smiles = "CCO"  # Ethanol
print(f"=== Molecular Properties for {smiles} ===\n")

## Step 1: Calculate molecular weight
print("Step 1: Molecular Weight")
result = await client.client.call_tool(
    "SMILESToWeight",
    arguments={"smiles": smiles}
)
result_data = client.parse_result(result)
print(f"{result_data}\n")

## Step 2: Calculate molecular formula
print("Step 2: Molecular Formula")
result = await client.client.call_tool(
    "GetMolFormula",
    arguments={"smiles": smiles}
)
result_data = client.parse_result(result)
print(f"{result_data}\n")

## Step 3: Calculate exact molecular weight
print("Step 3: Exact Molecular Weight")
result = await client.client.call_tool(
    "GetExactMolceularWeight",
    arguments={"smiles": smiles}
)
result_data = client.parse_result(result)
print(f"{result_data}\n")

## Step 4: Count atoms
print("Step 4: Atom Count")
result = await client.client.call_tool(
    "GetAtomsNum",
    arguments={"smiles": smiles}
)
result_data = client.parse_result(result)
print(f"{result_data}\n")

## Step 5: Count heavy atoms
print("Step 5: Heavy Atom Count")
result = await client.client.call_tool(
    "GetHeavyAtomsNum",
    arguments={"smiles": smiles}
)
result_data = client.parse_result(result)
print(f"{result_data}\n")

await client.disconnect()
```

### Tool Descriptions

**SciToolAgent-Chem Server:**
- `SMILESToWeight`: Calculate average molecular weight
  - Args: `smiles` (str) - SMILES string
  - Returns: Molecular weight in g/mol

- `GetMolFormula`: Calculate molecular formula
  - Args: `smiles` (str) - SMILES string
  - Returns: Molecular formula (e.g., C₂H₆O)

- `GetExactMolceularWeight`: Calculate exact (monoisotopic) molecular weight
  - Args: `smiles` (str) - SMILES string
  - Returns: Exact mass (most abundant isotope composition)

- `GetAtomsNum`: Count total number of atoms
  - Args: `smiles` (str) - SMILES string
  - Returns: Total atom count (excluding hydrogens in implicit SMILES)

- `GetHeavyAtomsNum`: Count heavy atoms (non-hydrogen)
  - Args: `smiles` (str) - SMILES string
  - Returns: Heavy atom count

### Input/Output

**Input:**
- `smiles`: Molecule in SMILES format (e.g., "CCO", "c1ccccc1", "CC(=O)O")

**Output:**
- **Molecular Weight**: Average mass based on natural isotope abundances (g/mol or Da)
- **Molecular Formula**: Elemental composition (CₓHᵧNᵢOⱼ...)
- **Exact Molecular Weight**: Monoisotopic mass (most abundant isotope for each element)
- **Atom Count**: Total number of atoms in the molecule
- **Heavy Atom Count**: Number of non-hydrogen atoms

### Use Cases

- Drug-likeness assessment (molecular weight screening)
- Mass spectrometry data interpretation
- Stoichiometry calculations
- Chemical database queries
- Lipinski's Rule of Five evaluation
- Compound library characterization
- Quality control for chemical synthesis

### Molecular Weight Types

- **Average MW**: Used for general calculations, based on natural isotope distribution
- **Exact MW**: Used for mass spectrometry, based on most abundant isotopes
- **Difference**: Minimal for small molecules, can be significant for large biomolecules

Example:
- Ethanol (C₂H₆O): Average MW = 46.07 Da, Exact MW = 46.0418 Da

### Additional Molecular Property Tools

The SciToolAgent-Chem server provides 160+ additional tools including:
- `GetRotatableBondsNum`: Count rotatable bonds
- `GetHBDNum`/`GetHBANum`: Hydrogen bond donors/acceptors
- `GetRingsNum`: Count ring systems
- `GetTPSA`: Calculate topological polar surface area (TPSA)
- `GetCrippenDescriptors`: Calculate logP and molar refractivity
- `GetLipinskiHBDNum`/`GetLipinskiHBANum`: Lipinski rule parameters
- `GetAromaticRingsNum`: Count aromatic rings
- `GetFractionCSP3`: Calculate fraction of sp³ carbons

### Lipinski's Rule of Five

For drug-likeness, molecules should satisfy:
1. Molecular weight ≤ 500 Da
2. LogP ≤ 5
3. Hydrogen bond donors ≤ 5
4. Hydrogen bond acceptors ≤ 10

Use the property calculation tools to assess these criteria.

More from InternScience/scp

SkillDescription
admet_druglikeness_reportADMET & Drug-Likeness Report - Generate comprehensive ADMET and drug-likeness report: molecular properties, H-bond analysis, hydrophobicity, topology, and ADMET prediction. Use this skill for medicinal chemistry tasks involving calculate mol basic info calculate mol hbond calculate mol hydrophobicity calculate mol topology pred molecule admet. Combines 5 tools from 2 SCP server(s).
affinity_maturationAffinity Maturation Pipeline - Affinity maturation: compute binding affinity, predict mutations, compute hydrophilicity, and predict drug-target interaction. Use this skill for antibody engineering tasks involving ComputeAffinityCalculator zero shot sequence prediction ComputeHydrophilicity PredictDrugTargetInteraction. Combines 4 tools from 3 SCP server(s).
alanine_scanning_pipelineAlanine Scanning Mutagenesis Pipeline - Alanine scanning: design scan, compute properties for each mutant, predict interactions, and compare. Use this skill for protein biochemistry tasks involving AlanineScanningDesigner ComputeProtPara PredictDrugTargetInteraction calculate protein sequence properties. Combines 4 tools from 3 SCP server(s).
aliphatic_ring_analysisRing System Analysis - Analyze ring systems: count aliphatic carbocycles, analyze aromaticity, compute topology, and structure complexity. Use this skill for organic chemistry tasks involving GetAliphaticCarbocyclesNum AromaticityAnalyzer calculate mol topology calculate mol structure complexity. Combines 4 tools from 3 SCP server(s).
alphafold_structure_pipelineAlphaFold Structure Analysis Pipeline - AlphaFold pipeline: download predicted structure, predict pockets, extract sequence, and compute properties. Use this skill for computational biology tasks involving download alphafold structure run fpocket extract pdb sequence calculate pdb basic info. Combines 4 tools from 3 SCP server(s).
antibody_drug_developmentAntibody Drug Development - Develop antibody drug: target protein analysis, biotherapeutic lookup, protein properties, and interaction prediction. Use this skill for biologics tasks involving get uniprotkb entry by accession get biotherapeutic by name ComputeProtPara ComputeHydrophilicity. Combines 4 tools from 3 SCP server(s).
antibody_target_analysisAntibody-Target Analysis - Analyze an antibody target: UniProt protein info, InterPro domains, protein properties, and biotherapeutic data from ChEMBL. Use this skill for immunology tasks involving get uniprotkb entry by accession query interpro ComputeProtPara get biotherapeutic by name. Combines 4 tools from 4 SCP server(s).
atc_drug_classificationATC Drug Classification Lookup - Look up drug in ATC classification: ChEMBL ATC class, FDA drug info, PubChem compound, and mechanism of action. Use this skill for pharmacology tasks involving get atc class by level5 get mechanism of action by drug name get compound by name get drug by name. Combines 4 tools from 3 SCP server(s).
atmospheric-science-calculationsCalculate atmospheric parameters including Coriolis parameter, geostrophic wind, heat index, potential temperature, and dewpoint for meteorology and climate science.
binding_site_characterizationBinding Site Characterization - Characterize binding sites: predict pockets with fpocket and P2Rank, get binding site info from ChEMBL, and visualize. Use this skill for structural biology tasks involving run fpocket pred pocket prank get binding site by id visualize protein. Combines 4 tools from 3 SCP server(s).