load_chemistrix_library.ipynb 8.05 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# How to load new libraries to Chemical Checker infrastructure"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "## Load library files to datasource table\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "sys.path.append(\"/aloy/home/oguitart/projects/source/chemical_checker/chemicalchecker\")\n",
    "\n",
    "os.environ[\"CC_CONFIG\"] = '/aloy/home/oguitart/projects/source/chemical_checker/chemicalchecker/tests/data/config.json'\n",
    "\n",
    "\n",
    "from chemicalchecker.util import Config\n",
    "\n",
    "from chemicalchecker.database import Datasource\n",
    "\n",
    "\n",
    "\n",
    "biur_real = {'name':\"biur_real\",'url':\"file:///aloy/scratch/sbnb-adm/checker/local_downloads/BIUR_20100326.sdf\",\n",
    "             'permanent':True,'enabled':False,'user':\"\",'password':\"\",'description':\"ChemistryX Biur real library\",\n",
    "             'molrepo_name':\"biur_real\",'molrepo_file':\"BIUR_20100326.sdf\",'is_db':False}\n",
    "biur_virtual = {'name':\"biur_virtual\",'url':\"file:///aloy/scratch/sbnb-adm/checker/local_downloads/VIRTUAL_BIUR_POR_MW.tar.gz\",\n",
    "                'permanent':True,'enabled':False,'user':\"\",'password':\"\",'description':\"ChemistryX Biur virtual library\",\n",
    "                'molrepo_name':\"biur_virtual\",'molrepo_file':\"VIRTUAL_BIUR_POR_MW\",'is_db':False}\n",
    "\n",
    "\n",
    "Datasource.add(biur_real)\n",
    "Datasource.add(biur_virtual)\n"
   ]
  },
49
50
51
52
53
54
55
56
57
58
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Add Library parser\n",
    "\n",
    "Check the *package/chemicalchecker/util/parser/parser.py* file and add a method for each one of the new libraries to parse those libraries. \n",
    "The new method to parse the library should have the same name as the **molrepo_name** used in the datasource table. The output of the method should be the same as the other methods used in the **parser.py** file."
   ]
  },
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Download  & parse datasource associated to library \"biur_real\"\n",
    "\n",
    "1. Download the datasource files\n",
    "2. Parse downloaded files and load it to the molrepo table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "sys.path.append(\"/aloy/home/oguitart/projects/source/chemical_checker/chemicalchecker\")\n",
    "\n",
    "os.environ[\"CC_CONFIG\"] = '/aloy/home/oguitart/projects/source/chemical_checker/chemicalchecker/tests/data/config.json'\n",
    "\n",
    "\n",
    "from chemicalchecker.util import Config\n",
    "\n",
    "from chemicalchecker.database import Datasource, Molrepo\n",
    "\n",
    "# This method downloads all datasources related to this library \n",
    "# and parse the files to load the new data to the molrepo table\n",
    "\n",
    "Molrepo.from_molrepo_name(\"biur_real\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Download datasource associated to library \"biur_virtual\"\n",
    "\n",
    "1. Download the datasource files\n",
    "2. Parse downloaded files and load it to the molrepo table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "sys.path.append(\"/aloy/home/oguitart/projects/source/chemical_checker/chemicalchecker\")\n",
    "\n",
    "os.environ[\"CC_CONFIG\"] = '/aloy/home/oguitart/projects/source/chemical_checker/chemicalchecker/tests/data/config.json'\n",
    "\n",
    "\n",
    "from chemicalchecker.util import Config\n",
    "\n",
    "from chemicalchecker.database import Datasource, Molrepo\n",
    "\n",
    "# This method downloads all datasources related to this library \n",
    "# and parse the files to load the new data to the molrepo table\n",
    "\n",
    "Molrepo.from_molrepo_name(\"biur_virtual\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Calculate the molecular properties and store them for library \"biur_real\"\n",
    "\n",
135
    "It will also add the missing molecules to the structure table\n",
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
    "It will create jobs to do this task in the cluster.  \n",
    "It waits for a molecular property calculation to finish before submitting another one. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import shutil\n",
    "\n",
    "sys.path.append(\"/aloy/home/oguitart/projects/source/chemical_checker/chemicalchecker\")\n",
    "\n",
    "os.environ[\"CC_CONFIG\"] = '/aloy/home/oguitart/projects/source/chemical_checker/chemicalchecker/tests/data/config.json'\n",
    "\n",
    "\n",
    "from chemicalchecker.database import Molprop, Structure\n",
    "from chemicalchecker.database import Molrepo\n",
    "from chemicalchecker.util import HPC\n",
    "from chemicalchecker.util import Config\n",
    "\n",
    "\n",
    "molprops = ['fp2d','fp3d','subskeys','scaffolds','physchem']\n",
    "\n",
    "molrepo_ik_inchi = Molrepo.get_fields_by_molrepo_name(\"biur_real\",[\"inchikey\",\"inchi\"])\n",
    "\n",
    "for mol in molprops:\n",
    "\n",
    "    job_path = \"/aloy/scratch/oguitart/jobs_molprop_\" + mol\n",
    "    if os.path.isdir(job_path):\n",
    "        shutil.rmtree(job_path)\n",
    "    os.mkdir(job_path)\n",
    "\n",
    "    molprop = Molprop(mol)\n",
    "\n",
    "    # This method sends the job and waits for the job to finish\n",
    "    cluster = molprop.molprop_hpc(job_path,molrepo_ik_inchi)\n",
    "   \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Calculate the molecular properties and store them for library \"biur_virtual\"\n",
    "\n",
    "It will create jobs to do this task in the cluster.  \n",
    "It waits for a molecular property calculation to finish before submitting another one."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import shutil\n",
    "\n",
    "sys.path.append(\"/aloy/home/oguitart/projects/source/chemical_checker/chemicalchecker\")\n",
    "\n",
    "os.environ[\"CC_CONFIG\"] = '/aloy/home/oguitart/projects/source/chemical_checker/chemicalchecker/tests/data/config.json'\n",
    "\n",
    "cc_config = '/aloy/home/oguitart/projects/source/chemical_checker/chemicalchecker/tests/data/config.json'\n",
    "\n",
    "from chemicalchecker.database import Molprop, Structure\n",
    "from chemicalchecker.database import Molrepo\n",
    "from chemicalchecker.util import HPC\n",
    "from chemicalchecker.util import Config\n",
    "\n",
    "\n",
    "molprops = ['fp2d','fp3d','subskeys','scaffolds','physchem']\n",
    "\n",
    "molrepo_ik_inchi = Molrepo.get_fields_by_molrepo_name(\"biur_virtual\",[\"inchikey\",\"inchi\"])\n",
    "\n",
    "for mol in molprops:\n",
    "\n",
    "    job_path = \"/aloy/scratch/oguitart/jobs_molprop_\" + mol\n",
    "    if os.path.isdir(job_path):\n",
    "        shutil.rmtree(job_path)\n",
    "    os.mkdir(job_path)\n",
    "\n",
    "    molprop = Molprop(mol)\n",
    "\n",
    "    # This method sends the job and waits for the job to finish\n",
    "    cluster = molprop.molprop_hpc(job_path,molrepo_ik_inchi)\n",
    "    \n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}