<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Compute conformer energies for a small molecule\n",
    "\n",
    "This notebook illustrates reading conformers of a molecule from an SDF file and computation of vacuum conformer energies using a SMIRNOFF force field."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8a309346d60f48d5b897d515002b6f42",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "_ColormakerRegistry()"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 unique molecule(s) loaded, with 10 total conformers\n"
     ]
    }
   ],
   "source": [
    "# Load in the molecule and its conformers.\n",
    "# You would start here if you had your own SDF input files.\n",
    "# Note that all conformers of the same molecule are loaded as separate Molecule objects\n",
    "from openforcefield.topology import Molecule\n",
    "#loaded_molecules = Molecule.from_file('imatinib_conformers.sdf')\n",
    "loaded_molecules = Molecule.from_file('ruxolitinib_conformers.sdf')\n",
    "# Collatate all conformers of the same molecule\n",
    "# NOTE: This isn't necessary if you have already loaded or created multi-conformer molecules;\n",
    "# it is just needed because our SDF reader does not automatically collapse conformers.\n",
    "molecules = [loaded_molecules[0]]\n",
    "for molecule in loaded_molecules[1:]:\n",
    "    if molecule == molecules[-1]:\n",
    "        for conformer in molecule.conformers:\n",
    "            molecules[-1].add_conformer(conformer)\n",
    "    else:\n",
    "        molecules.append(molecule)\n",
    "\n",
    "n_molecules = len(molecules)\n",
    "n_conformers = sum([mol.n_conformers for mol in molecules])\n",
    "print(f'{n_molecules} unique molecule(s) loaded, with {n_conformers} total conformers')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the openff-1.0.0 force field appropriate for vacuum calculations (without constraints)\n",
    "from openforcefield.typing.engines.smirnoff import ForceField\n",
    "forcefield = ForceField('openff_unconstrained-1.1.0.offxml')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ruxolitinib : 10 conformers\n",
      "Conformer     0 /    10 :   34.921 kcal/mol\n",
      "Conformer     1 /    10 :   43.903 kcal/mol\n",
      "Conformer     2 /    10 :   79.537 kcal/mol\n",
      "Conformer     3 /    10 :   40.710 kcal/mol\n",
      "Conformer     4 /    10 :   41.273 kcal/mol\n",
      "Conformer     5 /    10 :   43.646 kcal/mol\n",
      "Conformer     6 /    10 :   42.257 kcal/mol\n",
      "Conformer     7 /    10 :   32.198 kcal/mol\n",
      "Conformer     8 /    10 :   38.401 kcal/mol\n",
      "Conformer     9 /    10 :   41.009 kcal/mol\n"
     ]
    }
   ],
   "source": [
    "# Loop over molecules and compute energies of each conformer\n",
    "for molecule in molecules:\n",
    "    print('%s : %d conformers' % (molecule.name, molecule.n_conformers))\n",
    "    # Create an OpenMM System for the small molecule in vacuum\n",
    "    system = forcefield.create_openmm_system(molecule.to_topology())\n",
    "    # Compute energy for all conformers\n",
    "    from simtk import openmm, unit\n",
    "    integrator = openmm.VerletIntegrator(1*unit.femtoseconds)\n",
    "    platform = openmm.Platform.getPlatformByName('Reference')\n",
    "    context = openmm.Context(system, integrator, platform)\n",
    "    for conformer_index, conformer in enumerate(molecule.conformers):\n",
    "        context.setPositions(conformer)\n",
    "        potential = context.getState(getEnergy=True).getPotentialEnergy()\n",
    "        print('Conformer %5d / %5d : %8.3f kcal/mol' % (conformer_index, molecule.n_conformers, potential/unit.kilocalories_per_mole))\n",
    "    # Clean up OpenMM Context\n",
    "    del context, integrator"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
<commit_msg>notebook cleanup<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Compute conformer energies for a small molecule\n",
    "\n",
    "This notebook illustrates reading conformers of a molecule from an SDF file and computation of vacuum conformer energies using a SMIRNOFF force field."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0c01201b3cb344f195580f00c5847ca3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "_ColormakerRegistry()"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 unique molecule(s) loaded, with 10 total conformers\n"
     ]
    }
   ],
   "source": [
    "# Load in the molecule and its conformers.\n",
    "# Note that all conformers of the same molecule are loaded as separate Molecule objects\n",
    "from openforcefield.topology import Molecule\n",
    "#loaded_molecules = Molecule.from_file('imatinib_conformers.sdf')\n",
    "loaded_molecules = Molecule.from_file('ruxolitinib_conformers.sdf')\n",
    "# Collatate all conformers of the same molecule\n",
    "# NOTE: This isn't necessary if you have already loaded or created multi-conformer molecules;\n",
    "# it is just needed because our SDF reader does not automatically collapse conformers.\n",
    "molecules = [loaded_molecules[0]]\n",
    "for molecule in loaded_molecules[1:]:\n",
    "    if molecule == molecules[-1]:\n",
    "        for conformer in molecule.conformers:\n",
    "            molecules[-1].add_conformer(conformer)\n",
    "    else:\n",
    "        molecules.append(molecule)\n",
    "\n",
    "n_molecules = len(molecules)\n",
    "n_conformers = sum([mol.n_conformers for mol in molecules])\n",
    "print(f'{n_molecules} unique molecule(s) loaded, with {n_conformers} total conformers')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the openff-1.1.0 force field appropriate for vacuum calculations (without constraints)\n",
    "from openforcefield.typing.engines.smirnoff import ForceField\n",
    "forcefield = ForceField('openff_unconstrained-1.1.0.offxml')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ruxolitinib : 10 conformers\n",
      "Conformer     0 /    10 :   34.921 kcal/mol\n",
      "Conformer     1 /    10 :   43.903 kcal/mol\n",
      "Conformer     2 /    10 :   79.537 kcal/mol\n",
      "Conformer     3 /    10 :   40.710 kcal/mol\n",
      "Conformer     4 /    10 :   41.273 kcal/mol\n",
      "Conformer     5 /    10 :   43.646 kcal/mol\n",
      "Conformer     6 /    10 :   42.257 kcal/mol\n",
      "Conformer     7 /    10 :   32.198 kcal/mol\n",
      "Conformer     8 /    10 :   38.401 kcal/mol\n",
      "Conformer     9 /    10 :   41.009 kcal/mol\n"
     ]
    }
   ],
   "source": [
    "# Loop over molecules and compute energies of each conformer\n",
    "for molecule in molecules:\n",
    "    print('%s : %d conformers' % (molecule.name, molecule.n_conformers))\n",
    "    # Create an OpenMM System for the small molecule in vacuum\n",
    "    system = forcefield.create_openmm_system(molecule.to_topology())\n",
    "    # Compute energy for all conformers\n",
    "    from simtk import openmm, unit\n",
    "    integrator = openmm.VerletIntegrator(1*unit.femtoseconds)\n",
    "    platform = openmm.Platform.getPlatformByName('Reference')\n",
    "    context = openmm.Context(system, integrator, platform)\n",
    "    for conformer_index, conformer in enumerate(molecule.conformers):\n",
    "        context.setPositions(conformer)\n",
    "        potential = context.getState(getEnergy=True).getPotentialEnergy()\n",
    "        print('Conformer %5d / %5d : %8.3f kcal/mol' % (conformer_index, molecule.n_conformers, potential/unit.kilocalories_per_mole))\n",
    "    # Clean up OpenMM Context\n",
    "    del context, integrator"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}

{'fraction_non_alphanumeric': 0.15410526315789475, 'fraction_numerical': 0.02894736842105263, 'mean_word_length': 2.6249523082792825, 'pattern_counts': {'":': 100, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3013586', 'n_tokens_mistral': 3554, 'n_tokens_neox': 3275, 'n_words': 725}