Communitygithub.com

molecular-dynamics

OpenMMとMDAnalysisを用いて分子動力学シミュレーションを実行・解析します。タンパク質/低分子系の構築、力場の定義、エネルギー最小化、本番MD、トラジェクトリ解析(RMSD、RMSF、接触マップ、自由エネルギー曲面)を行います。構造生物学、薬剤結合、生物物理学向けです。

molecular-dynamics とは?

分子動力学(MD)シミュレーションスキルは、OpenMMとMDAnalysisという2つの強力なオープンソースライブラリを統合し、タンパク質や低分子系の動的挙動を原子レベルで解析します。OpenMMはGPU対応の高性能シミュレーションエンジンであり、Particle Mesh Ewaldによる長距離静電相互作用、Langevin熱浴による温度制御、水素結合拘束(2 fsタイムステップ許容)などの高度な機能を提供します。MDAnalysisは、シミュレーション後のトラジェクトリ解析を包括的にサポートし、RMSD/RMSF解析、残基間接触マップ、自由エネルギー曲面の計算、主成分分析を実現します。このスキルは、タンパク質安定性評価、薬剤結合シミュレーション、コンフォメーション変化の探索、タンパク質間相互作用の解析、膜タンパク質系のシミュレーションなど、構造生物学や生物物理学の多様な課題に対応可能です。システム構築からエネルギー最小化、NVT/NPT平衡化、本番シミュレーション、時系列・熱力学解析までの全工程をPythonスクリプトで一貫して実行できるため、計算科学者や生化学者にとって強力なワークフローとなります。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/skills/molecular-dynamics

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

分子動力学

概要

分子動力学(MD)シミュレーションは、ニュートンの運動方程式を数値積分することで分子系の時間発展を計算的にモデル化します。このスキルでは、以下の2つの補完的なツールを扱います。

インストール方法:

conda install -c conda-forge openmm mdanalysis nglview
# または
uv pip install openmm mdanalysis

このスキルを使用すべき場合

以下のような場合に分子動力学を使用します。

  • タンパク質安定性解析:変異はタンパク質の動的挙動にどのように影響するか?
  • 薬剤結合シミュレーション:リガンドの結合モードと滞留時間を特徴づける
  • 構造サンプリング:タンパク質の柔軟性と構造変化を探る
  • タンパク質間相互作用:界面ダイナミクスと結合エネルギーをモデル化する
  • RMSD/RMSF解析:基準構造からの構造的ゆらぎを定量化する
  • 自由エネルギー推定:結合自由エネルギーまたはコンフォメーション自由エネルギーを計算する
  • 膜シミュレーション:脂質二重層中のタンパク質をモデル化する
  • 天然変性タンパク質:IDRのコンフォメーションアンサンブルを研究する

コアワークフロー:OpenMMシミュレーション

1. システム準備

from openmm.app import *
from openmm import *
from openmm.unit import *
import sys

def prepare_system_from_pdb(pdb_file, forcefield_name="amber14-all.xml",
                              water_model="amber14/tip3pfb.xml"):
    """
    PDBファイルからOpenMMシステムを準備する。

    Args:
        pdb_file: クリーニング済みPDBファイルへのパス(生のPDBファイルにはPDBFixerを使用)
        forcefield_name: 力場XMLファイル
        water_model: 水モデルXMLファイル

    Returns:
        pdb, forcefield, system, topography
    """
    # PDBの読み込み
    pdb = PDBFile(pdb_file)

    # 力場の読み込み
    forcefield = ForceField(forcefield_name, water_model)

    # 水素原子の追加と溶媒和
    modeller = Modeller(pdb.topology, pdb.positions)
    modeller.addHydrogens(forcefield)

    # 溶媒ボックスの追加(10 Åのパディング、150 mM NaCl)
    modeller.addSolvent(
        forcefield,
        model='tip3p',
        padding=10*angstroms,
        ionicStrength=0.15*molar
    )

    print(f"System: {modeller.topology.getNumAtoms()} atoms, "
          f"{modeller.topology.getNumResidues()} residues")

    # システムの作成
    system = forcefield.createSystem(
        modeller.topology,
        nonbondedMethod=PME,         # 長距離静電相互作用にはParticle Mesh Ewald
        nonbondedCutoff=1.0*nanometer,
        constraints=HBonds,           # 水素結合を拘束(2 fsのタイムステップを可能にする)
        rigidWater=True,
        ewaldErrorTolerance=0.0005
    )

    return modeller, system

2. エネルギー最小化

from openmm.app import *
from openmm import *
from openmm.unit import *

def minimize_energy(modeller, system, output_pdb="minimized.pdb",
                     max_iterations=1000, tolerance=10.0):
    """
    系から立体障害を取り除くためにエネルギー最小化を行う。

    Args:
        modeller: トポロジーと位置を持つModellerオブジェクト
        system: OpenMM System
        output_pdb: 最小化された構造の保存先パス
        max_iterations: 最小化ステップの最大数
        tolerance: 収束基準(kJ/mol/nm)

    Returns:
        最小化された位置を持つシミュレーションオブジェクト
    """
    # 積分器の設定(最小化には関係しない)
    integrator = LangevinMiddleIntegrator(300*kelvin, 1/picosecond, 0.004*picoseconds)

    # シミュレーションの作成
    # 可能であればGPUを使用(CUDAまたはOpenCL)、CPUにフォールバック
    try:
        platform = Platform.getPlatformByName('CUDA')
        properties = {'DeviceIndex': '0', 'Precision': 'mixed'}
    except Exception:
        try:
            platform = Platform.getPlatformByName('OpenCL')
            properties = {}
        except Exception:
            platform = Platform.getPlatformByName('CPU')
            properties = {}

    simulation = Simulation(
        modeller.topology, system, integrator,
        platform, properties
    )
    simulation.context.setPositions(modeller.positions)

    # 初期エネルギーの確認
    state = simulation.context.getState(getEnergy=True)
    print(f"Initial energy: {state.getPotentialEnergy()}")

    # 最小化
    simulation.minimizeEnergy(
        tolerance=tolerance*kilojoules_per_mole/nanometer,
        maxIterations=max_iterations
    )

    state = simulation.context.getState(getEnergy=True, getPositions=True)
    print(f"Minimized energy: {state.getPotentialEnergy()}")

    # 最小化された構造を保存
    with open(output_pdb, 'w') as f:
        PDBFile.writeFile(simulation.topology, state.getPositions(), f)

    return simulation

3. NVT平衡化

from openmm.app import *
from openmm import *
from openmm.unit import *

def run_nvt_equilibration(simulation, n_steps=50000, temperature=300,
                            report_interval=1000, output_prefix="nvt"):
    """
    NVT平衡化:一定のN, V, T。
    速度を目標温度に平衡化する。

    Args:
        simulation: OpenMM Simulation(最小化後)
        n_steps: MDステップ数(50000 × 2fs = 100 ps)
        temperature: 温度(ケルビン)
        report_interval: データレポート間のステップ数
        output_prefix: トラジェクトリとログのファイル接頭辞
    """
    # NVT中は主鎖に位置拘束を追加
    # (オプション:重原子を拘束)

    # 温度設定
    simulation.context.setVelocitiesToTemperature(temperature*kelvin)

    # レポーター追加
    simulation.reporters = []

    # ログファイル
    simulation.reporters.append(
        StateDataReporter(
            f"{output_prefix}_log.txt",
            report_interval,
            step=True,
            potentialEnergy=True,
            kineticEnergy=True,
            temperature=True,
            volume=True,
            speed=True
        )
    )

    # DCDトラジェクトリ(コンパクトなバイナリ形式)
    simulation.reporters.append(
        DCDReporter(f"{output_prefix}_traj.dcd", report_interval)
    )

    print(f"Running NVT equilibration: {n_steps} steps ({n_steps*2/1000:.1f} ps)")
    simulation.step(n_steps)
    print("NVT equilibration complete")

    return simulation

4. NPT平衡化とプロダクションラン

def run_npt_production(simulation, n_steps=500000, temperature=300, pressure=1.0,
                        report_interval=5000, output_prefix="npt"):
    """
    NPTプロダクションラン:一定のN, P, T。

    Args:
        n_steps: プロダクションステップ数(500000 × 2fs = 1 ns)
        temperature: 温度(ケルビン)
        pressure: 圧力(bar)
        report_interval: レポート間のステップ数
    """
    # 圧力制御のためのモンテカルロバロスタットを追加
    system = simulation.context.getSystem()
    system.addForce(MonteCarloBarostat(pressure*bar, temperature*kelvin, 25))
    simulation.context.reinitialize(preserveState=True)

    # レポーターを更新
    simulation.reporters = []
    simulation.reporters.append(
        StateDataReporter(
            f"{output_prefix}_log.txt",
            report_interval,
            step=True,
            potentialEnergy=True,
            temperature=True,
            density=True,
            speed=True
        )
    )
    simulation.reporters.append(
        DCDReporter(f"{output_prefix}_traj.dcd", report_interval)
    )

    # チェックポイントを保存
    simulation.reporters.append(
        CheckpointReporter(f"{output_prefix}_checkpoint.chk", 50000)
    )

    print(f"Running NPT production: {n_steps} steps ({n_steps*2/1000000:.2f} ns)")
    simulation.step(n_steps)
    print("Production MD complete")
    return simulation

MDAnalysisによるトラジェクトリ解析

1. トラジェクトリの読み込み

import MDAnalysis as mda
from MDAnalysis.analysis import rms, align, contacts
import numpy as np
import matplotlib.pyplot as plt

def load_trajectory(topology_file, trajectory_file):
    """
    MDAnalysisでMDトラジェクトリを読み込む。

    Args:
        topology_file: PDB、PSF、またはその他のトポロジーファイル
        trajectory_file: DCD、XTC、TRR、またはその他のトラジェクトリ
    """
    u = mda.Universe(topology_file, trajectory_file)
    print(f"Universe: {u.atoms.n_atoms} atoms, {u.trajectory.n_frames} frames")
    print(f"Time range: 0 to {u.trajectory.totaltime:.0f} ps")
    return u

2. RMSD解析

def compute_rmsd(u, selection="backbone", reference_frame=0):
    """
    選択された原子のRMSDを参照フレームに対して計算する。

    Args:
        u: MDAnalysis Universe
        selection: 原子選択文字列(MDAnalysis構文)
        reference_frame: 基準構造のフレームインデックス

    Returns:
        (time, rmsd) 値のnumpy配列
    """
    # トラジェクトリを整列してRMSDを最小化
    aligner = align.AlignTraj(u, u, select=selection, in_memory=True)
    aligner.run()

    # RMSDの計算
    R = rms.RMSD(u, select=selection, ref_frame=reference_frame)
    R.run()

    rmsd_data = R.results.rmsd  # 列: frame, time, RMSD
    return rmsd_data

def plot_rmsd(rmsd_data, title="RMSD over time", output_file="rmsd.png"):
    """シミュレーション時間に対するRMSDをプロットする。"""
    fig, ax = plt.subplots(figsize=(10, 4))
    ax.plot(rmsd_data[:, 1] / 1000, rmsd_data[:, 2], 'b-', linewidth=0.5)
    ax.set_xlabel("Time (ns)")
    ax.set_ylabel("RMSD (Å)")
    ax.set_title(title)
    ax.axhline(rmsd_data[:, 2].mean(), color='r', linestyle='--',
               label=f'Mean: {rmsd_data[:, 2].mean():.2f} Å')
    ax.legend()
    plt.tight_layout()
    plt.savefig(output_file, dpi=150)
    return fig

3. RMSF解析(残基ごとの柔軟性)

def compute_rmsf(u, selection="backbone", start_frame=0):
    """
    残基ごとのRMSF(柔軟性)を計算する。

    Returns:
        resids, rmsf_values 配列
    """
    # 原子の選択
    atoms = u.select_atoms(selection)

    # RMSFの計算
    R = rms.RMSF(atoms)
    R.run(start=start_frame)

    # 残基ごとに平均化
    resids = []
    rmsf_per_res = []
    for res in u.select_atoms(selection).residues:
        res_atoms = res.atoms.intersection(atoms)
        if len(res_atoms) > 0:
            resids.append(res.resid)
            rmsf_per_res.append(R.results.rmsf[res_atoms.indices].mean())

    return np.array(resids), np.array(rmsf_per_res)

4. タンパク質-リガンドコンタクト

def analyze_contacts(u, protein_sel="protein", ligand_sel="resname LIG",
                      radius=4.5, start_frame=0):
    """
    トラジェクトリ全体でのタンパク質-リガンドコンタクトを追跡する。

    Args:
        radius: コンタクト距離カットオフ(Å)
    """
    protein = u.select_atoms(protein_sel)
    ligand = u.select_atoms(ligand_sel)

    contact_frames = []
    for ts in u.trajectory[start_frame:]:
        # リガンドからの半径内にあるタンパク質原子を見つける
        distances = contacts.contact_matrix(
            protein.positions, ligand.positions, radius
        )
        contact_residues = set()
        for i in range(distances.shape[0]):
            if distances[i].any():
                contact_residues.add(protein.atoms[i].resid)
        contact_frames.append(contact_residues)

    return contact_frames

力場選択ガイド

システム推奨力場水モデル
標準的なタンパク質AMBER14(amber14-all.xml)TIP3P-FB
タンパク質 + 小分子AMBER14 + GAFF2TIP3P-FB
膜タンパク質CHARMM36mTIP3P
核酸AMBER99-bsc1 または AMBER14TIP3P
天然変性タンパク質ff19SB または CHARMM36mTIP3P

システム準備ツール

PDBFixer(生のPDBファイル用)

from pdbfixer import PDBFixer
from openmm.app import PDBFile

def fix_pdb(input_pdb, output_pdb, ph=7.0):
    """一般的なPDB問題を修正:欠落残基、原子、水素追加、標準化。"""
    fixer = PDBFixer(filename=input_pdb)
    fixer.findMissingResidues()
    fixer.findNonstandardResidues()
    fixer.replaceNonstandardResidues()
    fixer.removeHeterogens(True)    # 水/リガンドを除去
    fixer.findMissingAtoms()
    fixer.addMissingAtoms()
    fixer.addMissingHydrogens(ph)

    with open(output_pdb, 'w') as f:
        PDBFile.writeFile(fixer.topology, fixer.positions, f)

    return output_pdb

小分子用GAFF2(OpenFF Toolkit経由)

# リガンドパラメータ化には、OpenFF ToolkitまたはACPYPEを使用
# uv pip install openff-toolkit
from openff.toolkit import Molecule, ForceField as OFFForceField
from openff.interchange import Interchange

def parameterize_ligand(smiles, ff_name="openff-2.0.0.offxml"):
    """小分子用のGAFF2/OpenFFパラメータを生成する。"""
    mol = Molecule.from_smiles(smiles)
    mol.generate_conformers(n_conformers=1)

    off_ff = OFFForceField(ff_name)
    interchange = off_ff.create_interchange(mol.to_topology())
    return interchange

ベストプラクティス

  • MDの前に必ず最小化を行う:生のPDB構造には立体障害がある
  • プロダクションの前に平衡化する:NVT(50–100 ps)→ NPT(100–500 ps)→ プロダクション
  • GPUを使用する:GPU(CUDA/OpenCL)でのシミュレーションは10~100倍高速
  • HBonds拘束による2 fsのタイムステップ:標準。HMR(水素質量再分配)では4 fsを使用
  • 平衡化されたトラジェクトリのみを解析する:最初の20~50%は平衡化として破棄する
  • チェックポイントを保存する:MD実行は失敗することがある。チェックポイントにより再開可能
  • 周期境界条件:溶媒和系に必要
  • 静電相互作用にはPME:荷電系ではカットオフ法よりも正確

追加リソース

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

adaptyv

How to use the Adaptyv Bio Foundry API and Python SDK for protein experiment design, submission, and results retrieval. Use this skill whenever the user mentions Adaptyv, Foundry API, protein binding assays, protein screening experiments, BLI/SPR assays, thermostability assays, or wants to submit protein sequences for experimental characterization. Also trigger when code imports `adaptyv`, `adaptyv_sdk`, or `FoundryClient`, or references `foundry-api-public.adaptyvbio.com`.

aeon

This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.

alphagenome

Look up precomputed AlphaGenome Atlas effects for any GRCh38 single-nucleotide variant (AVI score with Phred and 18 SHAP feature attributions, plus raw and quantile scores for RNA-seq, DNase, ATAC, ChIP-TF, ChIP-histone, CAGE, PRO-cap, splicing, polyadenylation and contact-map tracks), score variants or scan windows on demand with the AlphaGenome model for human and mouse (variant scoring, in silico mutagenesis, REF-versus-ALT track prediction), and build Atlas website deep links. Use when the user mentions AlphaGenome, AlphaGenome Atlas, AVI or AlphaGenome Variant Impact, DeepMind variant effect prediction, or wants to prioritise or mechanistically interpret non-coding, regulatory, splicing, enhancer, promoter, or chromatin-accessibility effects of SNVs from a VCF, credible set, or region. Research use only; not a clinical tool.

analytical-method-validation

Plan, execute, and document validation, verification, and transfer of analytical procedures under the governing framework - ICH Q2(R2) and Q14, USP <1220>/<1225>/<1226>, ICH M10 bioanalytical, CLSI EP, or ISO/IEC 17025. Use for HPLC, LC-MS/MS, GC, CE, ICP-MS, dissolution, qNMR, qPCR, NIR, and ligand binding or cell-based assays whenever the question is whether a procedure is fit for its intended purpose. Triggers include

anndata

Data structure for annotated matrices in single-cell analysis. Use when working with .h5ad files or integrating with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.

arbor

Autonomously improve a real artifact (code, training recipe, agent harness, data pipeline, prompt) against an objective and an evaluator, using Hypothesis Tree Refinement (HTR) from the Arbor paper. Use this whenever someone wants to iteratively optimize something over many experiments without overfitting — e.g.

arboreto

Infer gene regulatory networks (GRNs) from gene expression data using scalable algorithms (GRNBoost2, GENIE3). Use when analyzing transcriptomics data (bulk RNA-seq, single-cell RNA-seq) to identify transcription factor-target gene relationships and regulatory interactions. Supports distributed computation for large-scale datasets.

astropy

Core Python library for astronomy and astrophysics workflows that need Astropy APIs, including units/quantities, coordinates, FITS I/O, tables, time systems, WCS, and cosmology. Use when implementing or debugging astronomical data analysis code with Astropy.

autoskill

Observe the user

benchling-integration

Benchling Python SDK and REST API integration for registry entities, inventory, ELN entries, workflows, Benchling Apps, and Data Warehouse queries. Use when automating lab data with benchling-sdk or the v2 API.

bgpt-paper-search

Search scientific papers and retrieve structured experimental data extracted from full-text studies via the BGPT MCP server. Returns 25+ fields per paper including methods, results, sample sizes, quality scores, and conclusions. Use for literature reviews, evidence synthesis, and finding experimental details not available in abstracts alone.

bids

>

biopython

Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.

bioservices

Unified Python interface to 40+ bioinformatics services. Use when querying multiple databases (UniProt, KEGG, ChEMBL, Reactome) in a single workflow with consistent API. Best for cross-database analysis, ID mapping across services. For quick single-database lookups use gget; for sequence/file manipulation use biopython.

bulk-rnaseq

End-to-end bulk RNA-seq orchestrator — takes raw FASTQ reads through QC and trimming (FastQC, fastp/Trim Galore), alignment and quantification (STAR, Salmon, featureCounts), assembles a gene-level counts matrix, then hands off to differential expression (pydeseq2), pathway/GSEA enrichment (pathway-enrichment), and publication figures (scientific-visualization). Use whenever the user has bulk RNA-seq reads or quant output and wants a complete, reproducible differential-expression workflow — e.g.

cellxgene-census

Query the CZ CELLxGENE Census programmatically for versioned public single-cell and spatial transcriptomics data. Use when you need population-scale cell metadata, gene expression slices, Census summary counts, source H5AD URIs/downloads, embeddings, spatial Census data, or reference atlas comparisons across organisms, tissues, diseases, assays, and cell types. For analyzing your own local single-cell data use scanpy, anndata, or scvi-tools.

cirq

Google quantum computing framework. Use when targeting Google Quantum AI hardware, designing noise-aware circuits, or running quantum characterization experiments. Best for Google hardware, noise modeling, and low-level circuit design. For IBM hardware use qiskit; for quantum ML with autodiff use pennylane; for physics simulations use qutip.

citation-management

Comprehensive citation management for academic research. Search OpenAlex, PubMed, and Google Scholar for papers, extract accurate metadata, validate citations, and generate properly formatted BibTeX entries. This skill should be used when you need to find papers, verify citation information, convert DOIs to BibTeX, or ensure reference accuracy in scientific writing.

clinical-decision-support

Prepare and validate research-only clinical decision-support evaluation, evidence-profile, cohort, survival, biomarker/model, privacy, and governance artifacts. Use for aggregate or synthetic research documentation and traceability—not patient care or live clinical operation.

clinical-reports

Create safety-bounded draft structures and run local deterministic checks for clinical case, diagnostic, trial, safety, and aggregate research reports. Use only with synthetic, de-identified, or aggregate inputs and verified source-fact manifests; every output requires qualified review.

関連スキル