Skip to content

Commit

Permalink
Added auto-generation of mol names if they are absent in sdf file. Mo…
Browse files Browse the repository at this point in the history
…l order in output text file is the same as in input sdf file for single compounds. License years were updated.
  • Loading branch information
DrrDom committed Mar 17, 2015
1 parent 0858eab commit 2e47c14
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
2 changes: 2 additions & 0 deletions canon.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def GetSirmsType(bonds):

def GetSirmsType2(mol, atoms):
b = []
# atoms = set(atoms)
for a in atoms:
# b.append(len(set(mol.bonds[a].keys()).intersection(atoms)))
tmp = 0
for a1 in mol.bonds[a].keys():
if a1 in atoms:
Expand Down
2 changes: 1 addition & 1 deletion files.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Author: Pavel Polishchuk
#
# Created: 06.06.2013
# Copyright: (c) Pavel Polishchuk 2013
# Copyright: (c) Pavel Polishchuk 2013-2015
# Licence: GPLv3
#-------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion mols.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Author: Pavel Polishchuk
#
# Created: 11.01.2013
# Copyright: (c) Pavel Polishchuk 2013
# Copyright: (c) Pavel Polishchuk 2013-2015
# Licence: GPLv3
#-------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion ppgfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Author: Pavel Polishchuk
#
# Created: 11.01.2013
# Copyright: (c) Pavel Polishchuk 2013
# Copyright: (c) Pavel Polishchuk 2013-2015
# Licence: GPLv3
#-------------------------------------------------------------------------------

Expand Down
33 changes: 21 additions & 12 deletions sdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
# Author: Pavel Polishchuk
#
# Created: 11.01.2013
# Copyright: (c) Pavel Polishchuk 2013
# Copyright: (c) Pavel Polishchuk 2013-2015
# Licence: GPLv3
#-------------------------------------------------------------------------------


import string
import random
from collections import OrderedDict

from mols import Mol3 as Mol
from files import ReadPropertyRange, RangedLetter

Expand All @@ -30,11 +34,16 @@ def ReadSDF(fname, opt_diff, fsetup, parse_stereo):
OUTPUT: dict of molecules, where key is the title of the moleculae taken from the first line of mol-record
"""

def MolstrToMol(molstr, opt_diff, parse_stereo):
def MolstrToMol(molstr, opt_diff, parse_stereo, num_mol):

mol = Mol()
mol.stereo = parse_stereo
mol.title = molstr[0]

if molstr[0] == '':
mol.title = 'autogenerated_mol_id_' + str(num_mol)
else:
mol.title = molstr[0]

natoms = int(molstr[3][0:3])
nbonds = int(molstr[3][3:6])

Expand Down Expand Up @@ -117,14 +126,14 @@ def MolstrToMol(molstr, opt_diff, parse_stereo):

return mol

mols = {}
mols = OrderedDict()
molstr = []
f = open(fname)
for line in f:
if line.find("$$$$") < 0:
molstr.append(line.rstrip())
else:
m = MolstrToMol(molstr, opt_diff, parse_stereo)
mols[m.title] = m
molstr = []
with open(fname) as f:
for line in f:
if line.find("$$$$") < 0:
molstr.append(line.rstrip())
else:
m = MolstrToMol(molstr, opt_diff, parse_stereo, len(mols) + 1)
mols[m.title] = m
molstr = []
return mols
10 changes: 6 additions & 4 deletions sirms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Author: Pavel Polishchuk
#
# Created: 01.01.2013
# Copyright: (c) Pavel Polishchuk 2013
# Copyright: (c) Pavel Polishchuk 2013-2015
# Licence: GPLv3
# Python Version: 3.2
#-------------------------------------------------------------------------------
Expand All @@ -18,6 +18,8 @@
import time
import files
from itertools import combinations, chain, product
from collections import OrderedDict

from sdf import ReadSDF
from ppgfunctions import *
from canon import LoadSirmsDict, GetCanonNameByDict, GenCanonName, GetSirmsType2, GetSirmsType
Expand All @@ -37,10 +39,10 @@ def SaveSimplexes(fname, sirms, ndigits=5):
f_out = open(fname, 'wt')
# get sorted unique simplex names
sirms_names = sorted(list(set(list(chain.from_iterable([list(s.keys()) for s in sirms.values()])))))
compound_names = sorted([k for k in sirms.keys()])
# compound_names = sorted([k for k in sirms.keys()])
f_out.write("Compounds\t" + "\t".join(sirms_names) + "\n")
s = "{:." + str(ndigits) + "f}"
for n in compound_names:
for n in sirms.keys():
line = []
for m in sirms_names:
value = sirms[n].get(m, 0)
Expand Down Expand Up @@ -324,7 +326,7 @@ def CalcSingleCompSirmsMP(mol_list, sirms_dict, opt_diff, opt_types, opt_noH, nc
"""
if opt_verbose:
print(' Single compounds calculation '.center(79, '-'))
d = {}
d = OrderedDict()
if abs(ncores) > 1:
p = Pool(processes=min(len(mol_list), abs(ncores)))
res = [p.apply_async(CalcSingleCompSirms, [mol, sirms_dict, opt_diff, opt_types, opt_noH, opt_verbose, frags])
Expand Down

0 comments on commit 2e47c14

Please sign in to comment.