Skip to content

Instantly share code, notes, and snippets.

@GerardBCN
Last active April 5, 2020 11:43
Show Gist options
  • Save GerardBCN/e42c596c7d9830002b7961950c885c50 to your computer and use it in GitHub Desktop.
Save GerardBCN/e42c596c7d9830002b7961950c885c50 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"from rdkit import Chem\n",
"from rdkit.Chem import AllChem\n",
"import pandas as pd\n",
"from tqdm import tqdm"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"799it [00:09, 85.79it/s] \n"
]
}
],
"source": [
"df = pd.read_csv(\"./SAMPL7/protein_ligand/fragments_screened.csv\", header=None)\n",
"fragments = df[1].values\n",
"mols = []\n",
"for i,frag in tqdm(enumerate(fragments), total=len(fragments)):\n",
" m = Chem.MolFromSmiles(frag) # Read SMILES\n",
" m.SetProp(\"_Name\",\"frag_{}\".format(i)) # Give the molecule a name\n",
" m = Chem.AddHs(m) # Add hydrogens\n",
" AllChem.EmbedMolecule(m) # Generate 3D coordinates\n",
" mols.append(m)\n",
"w = Chem.SDWriter('fragments.sdf')\n",
"for frag in mols: \n",
" w.write(frag)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment