http://wiki.docking.org/index.php?title=Rdkit_hlogp_batch.py&feed=atom&action=history
Rdkit hlogp batch.py - Revision history
2024-03-28T08:42:11Z
Revision history for this page on the wiki
MediaWiki 1.39.1
http://wiki.docking.org/index.php?title=Rdkit_hlogp_batch.py&diff=12447&oldid=prev
Jyoung at 19:15, 15 April 2020
2020-04-15T19:15:41Z
<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 19:15, 15 April 2020</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><pre>from __future__ import print_function</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><pre></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">###########################</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"># Written by Jennifer Young </ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"># Last revised April 2020 </ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"># Version 1.0 </ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">###########################</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>from __future__ import print_function</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>import pdb</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>import pdb</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>import itertools</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>import itertools</div></td></tr>
</table>
Jyoung
http://wiki.docking.org/index.php?title=Rdkit_hlogp_batch.py&diff=12442&oldid=prev
Frodo: asdf
2020-04-15T16:58:46Z
<p>asdf</p>
<p><b>New page</b></p><div><pre>from __future__ import print_function<br />
import pdb<br />
import itertools<br />
import sys<br />
import shlex<br />
import subprocess<br />
<br />
from rdkit.Chem import (<br />
MolFromSmiles,<br />
MolToSmiles,<br />
AddHs,<br />
)<br />
<br />
from rdkit.Chem.SaltRemover import (<br />
SaltRemover<br />
)<br />
<br />
from rdkit.Chem.Descriptors import MolLogP, MolWt<br />
<br />
def scale_logp_value(logp):<br />
if logp < -9.0:<br />
logp = -9.0<br />
elif logp > 9.0:<br />
logp = 9.0<br />
elif logp < 0 or logp >= 5.0:<br />
logp = 100*int(logp)<br />
elif logp >= 0.0 or logp < 1:<br />
logp = 10*int(10*logp)<br />
elif logp >= 1.0 or logp < 4:<br />
logp = int(100*logp)<br />
elif logp >=4 or logp < 5:<br />
logp = 10*int(10*logp)<br />
return logp<br />
<br />
if __name__ == '__main__':<br />
if len(sys.argv) != 3:<br />
print('Usage: python rdkit_hlogp_batch.py <smiles> <batch_size>')<br />
exit()<br />
<br />
BATCH_SIZE = int(sys.argv[2])<br />
hlogp_list = list()<br />
with open(sys.argv[1]) as smiles_file:<br />
file_lines = smiles_file.readlines()<br />
for line in file_lines:<br />
if line.strip():<br />
smiles, cid = str(line).strip().split()[:2]<br />
mol = MolFromSmiles(smiles)<br />
remover = SaltRemover()<br />
res, deleted = remover.StripMolWithDeleted(mol)<br />
if res is not None:<br />
res.SetProp('_Name', cid)<br />
logp = MolLogP(res)<br />
num_heavy_atoms = res.GetNumHeavyAtoms()<br />
if num_heavy_atoms > 99:<br />
num_heavy_atoms = 99<br />
scaled_logp = scale_logp_value(logp)<br />
if logp < 0.0:<br />
sign = 'M'<br />
#remove the minus sign so it's not printed<br />
scaled_logp = scaled_logp * -1<br />
else:<br />
sign = 'P'<br />
key_string = 'H{:02}{}{:03}'.format(num_heavy_atoms, sign, scaled_logp)<br />
<br />
#store in list up to batch size, then write out to new file<br />
final_string = '{0} {1} {2}\n'.format(smiles, cid, key_string)<br />
hlogp_list.append(final_string)<br />
<br />
#write the key string to the file<br />
if len(hlogp_list) >= BATCH_SIZE:<br />
with open('{0}_hlogp'.format(sys.argv[1]), 'a+') as category_file:<br />
for entry in hlogp_list:<br />
category_file.write('{0}'.format(entry))<br />
#clear list because we already wrote these<br />
hlogp_list = list()<br />
#write remaining molecules to file<br />
for entry in hlogp_list:<br />
with open('{0}_hlogp'.format(sys.argv[1]), 'a+') as category_file:<br />
for entry in hlogp_list:<br />
category_file.write('{0}'.format(entry))<br />
</pre></div>
Frodo