Mercurial > repos > bgruening > ctb_rdkit_descriptors
changeset 8:a1c53f0533b0 draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
author | bgruening |
---|---|
date | Wed, 17 Feb 2021 12:59:43 +0000 |
parents | cf725c82c865 |
children | 0993ac4f4a23 |
files | dimorphite_dl.py rdkit_descriptors.py rdkit_descriptors.xml sdf_to_tab.py test-data/mol.pdb test-data/mol_pdb_charges.tab test-data/rdkit_descriptors_result1.tab test-data/rdkit_descriptors_subset.tab |
diffstat | 8 files changed, 384 insertions(+), 99 deletions(-) [+] |
line wrap: on
line diff
--- a/dimorphite_dl.py Tue Jul 28 08:43:19 2020 -0400 +++ b/dimorphite_dl.py Wed Feb 17 12:59:43 2021 +0000 @@ -1,3 +1,4 @@ +# flake8: noqa # Copyright 2018 Jacob D. Durrant # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +19,6 @@ """ from __future__ import print_function -import copy import os import argparse import sys
--- a/rdkit_descriptors.py Tue Jul 28 08:43:19 2020 -0400 +++ b/rdkit_descriptors.py Wed Feb 17 12:59:43 2021 +0000 @@ -1,44 +1,49 @@ #!/usr/bin/env python -from rdkit.Chem import Descriptors -from rdkit import Chem -import sys, os, re import argparse import inspect +import sys -def get_supplier( infile, format = 'smiles' ): +from rdkit import Chem +from rdkit.Chem import Descriptors + + +def get_supplier(infile, format='smiles'): """ - Returns a generator over a SMILES or InChI file. Every element is of RDKit + Returns a generator over a SMILES or InChI file. Every element is of RDKit molecule and has its original string as _Name property. """ with open(infile) as handle: for line in handle: line = line.strip() if format == 'smiles': - mol = Chem.MolFromSmiles( line, sanitize=True ) + mol = Chem.MolFromSmiles(line, sanitize=True) elif format == 'inchi': - mol = Chem.inchi.MolFromInchi( line, sanitize=True, removeHs=True, logLevel=None, treatWarningAsError=False ) + mol = Chem.inchi.MolFromInchi(line, sanitize=True, removeHs=True, logLevel=None, treatWarningAsError=False) if mol is None: yield False else: - mol.SetProp( '_Name', line.split('\t')[0] ) + mol.SetProp('_Name', line.split('\t')[0]) yield mol + def get_rdkit_descriptor_functions(): """ Returns all descriptor functions under the Chem.Descriptors Module as tuple of (name, function) """ - ret = [ (name, f) for name, f in inspect.getmembers( Descriptors ) if inspect.isfunction( f ) and not name.startswith( '_' ) ] + ret = [(name, f) for name, f in inspect.getmembers(Descriptors) if inspect.isfunction(f) and not name.startswith('_')] + # some which are not in the official Descriptors module we need to add manually + ret.extend([('FormalCharge', Chem.GetFormalCharge), ('SSSR', Chem.GetSSSR)]) ret.sort() return ret -def descriptors( mol, functions ): +def descriptors(mol, functions): """ Calculates the descriptors of a given molecule. """ for name, function in functions: - yield (name, function( mol )) + yield (name, function(mol)) if __name__ == "__main__": @@ -46,31 +51,44 @@ parser.add_argument('-i', '--infile', required=True, help='Path to the input file.') parser.add_argument("--iformat", help="Specify the input file format.") - parser.add_argument('-o', '--outfile', type=argparse.FileType('w+'), - default=sys.stdout, help="path to the result file, default it sdtout") + parser.add_argument('-o', '--outfile', type=argparse.FileType('w+'), + default=sys.stdout, + help="path to the result file, default is stdout") + + parser.add_argument('-s', '--select', default=None, + help="select a subset of comma-separated descriptors to use") parser.add_argument("--header", dest="header", action="store_true", - default=False, - help="Write header line.") + default=False, + help="Write header line.") args = parser.parse_args() if args.iformat == 'sdf': - supplier = Chem.SDMolSupplier( args.infile ) - elif args.iformat =='smi': - supplier = get_supplier( args.infile, format = 'smiles' ) + supplier = Chem.SDMolSupplier(args.infile) + elif args.iformat == 'smi': + supplier = get_supplier(args.infile, format='smiles') elif args.iformat == 'inchi': - supplier = get_supplier( args.infile, format = 'inchi' ) + supplier = get_supplier(args.infile, format='inchi') + elif args.iformat == 'pdb': + supplier = [Chem.MolFromPDBFile(args.infile)] + elif args.iformat == 'mol2': + supplier = [Chem.MolFromMol2File(args.infile)] functions = get_rdkit_descriptor_functions() + if args.select and args.select != 'None': + selected = args.select.split(',') + functions = [(name, f) for name, f in functions if name in selected] if args.header: - args.outfile.write( '%s\n' % '\t'.join( ['MoleculeID'] + [name for name, f in functions] ) ) + args.outfile.write('%s\n' % '\t'.join(['MoleculeID'] + [name for name, f in functions])) for mol in supplier: if not mol: continue - descs = descriptors( mol, functions ) - molecule_id = mol.GetProp("_Name") - args.outfile.write( "%s\n" % '\t'.join( [molecule_id]+ [str(round(res, 6)) for name, res in descs] ) ) - + descs = descriptors(mol, functions) + try: + molecule_id = mol.GetProp("_Name") + except KeyError: + molecule_id = Chem.MolToSmiles(mol) + args.outfile.write("%s\n" % '\t'.join([molecule_id] + [str(round(res, 6)) for name, res in descs]))
--- a/rdkit_descriptors.xml Tue Jul 28 08:43:19 2020 -0400 +++ b/rdkit_descriptors.xml Wed Feb 17 12:59:43 2021 +0000 @@ -1,9 +1,9 @@ <tool id="ctb_rdkit_descriptors" name="Descriptors" version="@TOOL_VERSION@+galaxy@GALAXY_VERSION@"> + <description>calculated with RDKit</description> <macros> <token name="@TOOL_VERSION@">2020.03.4</token> - <token name="@GALAXY_VERSION@">0</token> + <token name="@GALAXY_VERSION@">1</token> </macros> - <description>calculated with RDKit</description> <!--parallelism method="multi" split_inputs="infile" split_mode="to_size" split_size="10000" shared_inputs="" merge_outputs="outfile"></parallelism--> <requirements> <requirement type="package" version="@TOOL_VERSION@">rdkit</requirement> @@ -14,14 +14,222 @@ -i '${infile}' --iformat '${infile.ext}' -o '${outfile}' + #if $select_multiple: + -s '${select_multiple}' + #end if $header ]]> </command> <inputs> - <param name="infile" format="smi,sdf,mol2" type="data" label="Molecule data" - help="In SDF or SMILES format"/> + <param name="infile" format="smi,sdf,mol2,pdb,inchi" type="data" label="Molecule data" + help="In SDF, SMILES, MOL2, PDB or InChI format"/> <param name="header" type="boolean" label="Include the descriptor name as header" truevalue="--header" falsevalue="" checked="false" /> + <param name="select_multiple" type="select" label="Calculate only a subset of the descriptors" + multiple="true" help="If left blank, all descriptors will be calculated"> + <option value="BalabanJ">BalabanJ</option> + <option value="BertzCT">BertzCT</option> + <option value="Chi0">Chi0</option> + <option value="Chi0n">Chi0n</option> + <option value="Chi0v">Chi0v</option> + <option value="Chi1">Chi1</option> + <option value="Chi1n">Chi1n</option> + <option value="Chi1v">Chi1v</option> + <option value="Chi2n">Chi2n</option> + <option value="Chi2v">Chi2v</option> + <option value="Chi3n">Chi3n</option> + <option value="Chi3v">Chi3v</option> + <option value="Chi4n">Chi4n</option> + <option value="Chi4v">Chi4v</option> + <option value="EState_VSA1">EState_VSA1</option> + <option value="EState_VSA10">EState_VSA10</option> + <option value="EState_VSA11">EState_VSA11</option> + <option value="EState_VSA2">EState_VSA2</option> + <option value="EState_VSA3">EState_VSA3</option> + <option value="EState_VSA4">EState_VSA4</option> + <option value="EState_VSA5">EState_VSA5</option> + <option value="EState_VSA6">EState_VSA6</option> + <option value="EState_VSA7">EState_VSA7</option> + <option value="EState_VSA8">EState_VSA8</option> + <option value="EState_VSA9">EState_VSA9</option> + <option value="ExactMolWt">ExactMolWt</option> + <option value="FormalCharge">FormalCharge</option> + <option value="FpDensityMorgan1">FpDensityMorgan1</option> + <option value="FpDensityMorgan2">FpDensityMorgan2</option> + <option value="FpDensityMorgan3">FpDensityMorgan3</option> + <option value="FractionCSP3">FractionCSP3</option> + <option value="HallKierAlpha">HallKierAlpha</option> + <option value="HeavyAtomCount">HeavyAtomCount</option> + <option value="HeavyAtomMolWt">HeavyAtomMolWt</option> + <option value="Ipc">Ipc</option> + <option value="Kappa1">Kappa1</option> + <option value="Kappa2">Kappa2</option> + <option value="Kappa3">Kappa3</option> + <option value="LabuteASA">LabuteASA</option> + <option value="MaxAbsEStateIndex">MaxAbsEStateIndex</option> + <option value="MaxAbsPartialCharge">MaxAbsPartialCharge</option> + <option value="MaxEStateIndex">MaxEStateIndex</option> + <option value="MaxPartialCharge">MaxPartialCharge</option> + <option value="MinAbsEStateIndex">MinAbsEStateIndex</option> + <option value="MinAbsPartialCharge">MinAbsPartialCharge</option> + <option value="MinEStateIndex">MinEStateIndex</option> + <option value="MinPartialCharge">MinPartialCharge</option> + <option value="MolLogP">MolLogP</option> + <option value="MolMR">MolMR</option> + <option value="MolWt">MolWt</option> + <option value="NHOHCount">NHOHCount</option> + <option value="NOCount">NOCount</option> + <option value="NumAliphaticCarbocycles">NumAliphaticCarbocycles</option> + <option value="NumAliphaticHeterocycles">NumAliphaticHeterocycles</option> + <option value="NumAliphaticRings">NumAliphaticRings</option> + <option value="NumAromaticCarbocycles">NumAromaticCarbocycles</option> + <option value="NumAromaticHeterocycles">NumAromaticHeterocycles</option> + <option value="NumAromaticRings">NumAromaticRings</option> + <option value="NumHAcceptors">NumHAcceptors</option> + <option value="NumHDonors">NumHDonors</option> + <option value="NumHeteroatoms">NumHeteroatoms</option> + <option value="NumRadicalElectrons">NumRadicalElectrons</option> + <option value="NumRotatableBonds">NumRotatableBonds</option> + <option value="NumSaturatedCarbocycles">NumSaturatedCarbocycles</option> + <option value="NumSaturatedHeterocycles">NumSaturatedHeterocycles</option> + <option value="NumSaturatedRings">NumSaturatedRings</option> + <option value="NumValenceElectrons">NumValenceElectrons</option> + <option value="PEOE_VSA1">PEOE_VSA1</option> + <option value="PEOE_VSA10">PEOE_VSA10</option> + <option value="PEOE_VSA11">PEOE_VSA11</option> + <option value="PEOE_VSA12">PEOE_VSA12</option> + <option value="PEOE_VSA13">PEOE_VSA13</option> + <option value="PEOE_VSA14">PEOE_VSA14</option> + <option value="PEOE_VSA2">PEOE_VSA2</option> + <option value="PEOE_VSA3">PEOE_VSA3</option> + <option value="PEOE_VSA4">PEOE_VSA4</option> + <option value="PEOE_VSA5">PEOE_VSA5</option> + <option value="PEOE_VSA6">PEOE_VSA6</option> + <option value="PEOE_VSA7">PEOE_VSA7</option> + <option value="PEOE_VSA8">PEOE_VSA8</option> + <option value="PEOE_VSA9">PEOE_VSA9</option> + <option value="RingCount">RingCount</option> + <option value="SMR_VSA1">SMR_VSA1</option> + <option value="SMR_VSA10">SMR_VSA10</option> + <option value="SMR_VSA2">SMR_VSA2</option> + <option value="SMR_VSA3">SMR_VSA3</option> + <option value="SMR_VSA4">SMR_VSA4</option> + <option value="SMR_VSA5">SMR_VSA5</option> + <option value="SMR_VSA6">SMR_VSA6</option> + <option value="SMR_VSA7">SMR_VSA7</option> + <option value="SMR_VSA8">SMR_VSA8</option> + <option value="SMR_VSA9">SMR_VSA9</option> + <option value="SSSR">SSSR</option> + <option value="SlogP_VSA1">SlogP_VSA1</option> + <option value="SlogP_VSA10">SlogP_VSA10</option> + <option value="SlogP_VSA11">SlogP_VSA11</option> + <option value="SlogP_VSA12">SlogP_VSA12</option> + <option value="SlogP_VSA2">SlogP_VSA2</option> + <option value="SlogP_VSA3">SlogP_VSA3</option> + <option value="SlogP_VSA4">SlogP_VSA4</option> + <option value="SlogP_VSA5">SlogP_VSA5</option> + <option value="SlogP_VSA6">SlogP_VSA6</option> + <option value="SlogP_VSA7">SlogP_VSA7</option> + <option value="SlogP_VSA8">SlogP_VSA8</option> + <option value="SlogP_VSA9">SlogP_VSA9</option> + <option value="TPSA">TPSA</option> + <option value="VSA_EState1">VSA_EState1</option> + <option value="VSA_EState10">VSA_EState10</option> + <option value="VSA_EState2">VSA_EState2</option> + <option value="VSA_EState3">VSA_EState3</option> + <option value="VSA_EState4">VSA_EState4</option> + <option value="VSA_EState5">VSA_EState5</option> + <option value="VSA_EState6">VSA_EState6</option> + <option value="VSA_EState7">VSA_EState7</option> + <option value="VSA_EState8">VSA_EState8</option> + <option value="VSA_EState9">VSA_EState9</option> + <option value="fr_Al_COO">fr_Al_COO</option> + <option value="fr_Al_OH">fr_Al_OH</option> + <option value="fr_Al_OH_noTert">fr_Al_OH_noTert</option> + <option value="fr_ArN">fr_ArN</option> + <option value="fr_Ar_COO">fr_Ar_COO</option> + <option value="fr_Ar_N">fr_Ar_N</option> + <option value="fr_Ar_NH">fr_Ar_NH</option> + <option value="fr_Ar_OH">fr_Ar_OH</option> + <option value="fr_COO">fr_COO</option> + <option value="fr_COO2">fr_COO2</option> + <option value="fr_C_O">fr_C_O</option> + <option value="fr_C_O_noCOO">fr_C_O_noCOO</option> + <option value="fr_C_S">fr_C_S</option> + <option value="fr_HOCCN">fr_HOCCN</option> + <option value="fr_Imine">fr_Imine</option> + <option value="fr_NH0">fr_NH0</option> + <option value="fr_NH1">fr_NH1</option> + <option value="fr_NH2">fr_NH2</option> + <option value="fr_N_O">fr_N_O</option> + <option value="fr_Ndealkylation1">fr_Ndealkylation1</option> + <option value="fr_Ndealkylation2">fr_Ndealkylation2</option> + <option value="fr_Nhpyrrole">fr_Nhpyrrole</option> + <option value="fr_SH">fr_SH</option> + <option value="fr_aldehyde">fr_aldehyde</option> + <option value="fr_alkyl_carbamate">fr_alkyl_carbamate</option> + <option value="fr_alkyl_halide">fr_alkyl_halide</option> + <option value="fr_allylic_oxid">fr_allylic_oxid</option> + <option value="fr_amide">fr_amide</option> + <option value="fr_amidine">fr_amidine</option> + <option value="fr_aniline">fr_aniline</option> + <option value="fr_aryl_methyl">fr_aryl_methyl</option> + <option value="fr_azide">fr_azide</option> + <option value="fr_azo">fr_azo</option> + <option value="fr_barbitur">fr_barbitur</option> + <option value="fr_benzene">fr_benzene</option> + <option value="fr_benzodiazepine">fr_benzodiazepine</option> + <option value="fr_bicyclic">fr_bicyclic</option> + <option value="fr_diazo">fr_diazo</option> + <option value="fr_dihydropyridine">fr_dihydropyridine</option> + <option value="fr_epoxide">fr_epoxide</option> + <option value="fr_ester">fr_ester</option> + <option value="fr_ether">fr_ether</option> + <option value="fr_furan">fr_furan</option> + <option value="fr_guanido">fr_guanido</option> + <option value="fr_halogen">fr_halogen</option> + <option value="fr_hdrzine">fr_hdrzine</option> + <option value="fr_hdrzone">fr_hdrzone</option> + <option value="fr_imidazole">fr_imidazole</option> + <option value="fr_imide">fr_imide</option> + <option value="fr_isocyan">fr_isocyan</option> + <option value="fr_isothiocyan">fr_isothiocyan</option> + <option value="fr_ketone">fr_ketone</option> + <option value="fr_ketone_Topliss">fr_ketone_Topliss</option> + <option value="fr_lactam">fr_lactam</option> + <option value="fr_lactone">fr_lactone</option> + <option value="fr_methoxy">fr_methoxy</option> + <option value="fr_morpholine">fr_morpholine</option> + <option value="fr_nitrile">fr_nitrile</option> + <option value="fr_nitro">fr_nitro</option> + <option value="fr_nitro_arom">fr_nitro_arom</option> + <option value="fr_nitro_arom_nonortho">fr_nitro_arom_nonortho</option> + <option value="fr_nitroso">fr_nitroso</option> + <option value="fr_oxazole">fr_oxazole</option> + <option value="fr_oxime">fr_oxime</option> + <option value="fr_para_hydroxylation">fr_para_hydroxylation</option> + <option value="fr_phenol">fr_phenol</option> + <option value="fr_phenol_noOrthoHbond">fr_phenol_noOrthoHbond</option> + <option value="fr_phos_acid">fr_phos_acid</option> + <option value="fr_phos_ester">fr_phos_ester</option> + <option value="fr_piperdine">fr_piperdine</option> + <option value="fr_piperzine">fr_piperzine</option> + <option value="fr_priamide">fr_priamide</option> + <option value="fr_prisulfonamd">fr_prisulfonamd</option> + <option value="fr_pyridine">fr_pyridine</option> + <option value="fr_quatN">fr_quatN</option> + <option value="fr_sulfide">fr_sulfide</option> + <option value="fr_sulfonamd">fr_sulfonamd</option> + <option value="fr_sulfone">fr_sulfone</option> + <option value="fr_term_acetylene">fr_term_acetylene</option> + <option value="fr_tetrazole">fr_tetrazole</option> + <option value="fr_thiazole">fr_thiazole</option> + <option value="fr_thiocyan">fr_thiocyan</option> + <option value="fr_thiophene">fr_thiophene</option> + <option value="fr_unbrch_alkane">fr_unbrch_alkane</option> + <option value="fr_urea">fr_urea</option> + <option value="qed">qed</option> + </param> </inputs> <outputs> <data format="tabular" name="outfile" /> @@ -32,6 +240,18 @@ <param name="header" value="True" /> <output name="outfile" ftype='tabular' file="rdkit_descriptors_result1.tab" /> </test> + <test> + <param name="infile" ftype='sdf' value="CID_3037.sdf" /> + <param name="header" value="True" /> + <param name="select_multiple" value="qed,FormalCharge,MolWt" /> + <output name="outfile" ftype='tabular' file="rdkit_descriptors_subset.tab" /> + </test> + <test> + <param name="infile" ftype='pdb' value="mol.pdb" /> + <param name="header" value="False" /> + <param name="select_multiple" value="FormalCharge" /> + <output name="outfile" ftype='tabular' file="mol_pdb_charges.tab" /> + </test> </tests> <help> <![CDATA[ @@ -41,73 +261,40 @@ **What this tool does** | RDKit is an open source toolkit for cheminformatics and machine learning. -| This tool calculates various molecular descriptors for the input data. The table below shows a brief overview of the descriptors. +| This tool calculates various molecular descriptors for the input data. The table below shows a brief overview of the descriptors (or families of related descriptors) which are calculated. | - -+-----------------------------------+------------+ -| Descriptor/Descriptor Family | Language | -+===================================+============+ -| Gasteiger/Marsili Partial Charges | C++ | -+-----------------------------------+------------+ -| BalabanJ | Python | -+-----------------------------------+------------+ -| BertzCT | Python | -+-----------------------------------+------------+ -| Ipc | Python | -+-----------------------------------+------------+ -| HallKierAlpha | Python | -+-----------------------------------+------------+ -| Kappa1 - Kappa3 | Python | -+-----------------------------------+------------+ -| Chi0, Chi1 | Python | -+-----------------------------------+------------+ -| Chi0n - Chi4n | Python | -+-----------------------------------+------------+ -| Chi0v - Chi4v | Python | -+-----------------------------------+------------+ -| MolLogP | C++ | -+-----------------------------------+------------+ -| MolMR | C++ | -+-----------------------------------+------------+ -| MolWt | C++ | -+-----------------------------------+------------+ -| HeavyAtomCount | Python | -+-----------------------------------+------------+ -| HeavyAtomMolWt | Python | -+-----------------------------------+------------+ -| NHOHCount | C++ | -+-----------------------------------+------------+ -| NOCount | C++ | -+-----------------------------------+------------+ -| NumHAcceptors | C++ | -+-----------------------------------+------------+ -| NumHDonors | C++ | -+-----------------------------------+------------+ -| NumHeteroatoms | C++ | -+-----------------------------------+------------+ -| NumRotatableBonds | C++ | -+-----------------------------------+------------+ -| NumValenceElectrons | Python | -+-----------------------------------+------------+ -| RingCount | C++ | -+-----------------------------------+------------+ -| TPSA | C++ | -+-----------------------------------+------------+ -| LabuteASA | C++ | -+-----------------------------------+------------+ -| PEOE_VSA1 - PEOE_VSA14 | Python/C++ | -+-----------------------------------+------------+ -| SMR_VSA1 - SMR_VSA10 | Python/C++ | -+-----------------------------------+------------+ -| SlogP_VSA1 - SlogP_VSA12 | Python/C++ | -+-----------------------------------+------------+ -| EState_VSA1 - EState_VSA11 | Python | -+-----------------------------------+------------+ -| VSA_EState1 - VSA_EState10 | Python | -+-----------------------------------+------------+ -| Topliss fragments | Python | -+-----------------------------------+------------+ - +| - Gasteiger/Marsili Partial Charges +| - BalabanJ +| - BertzCT +| - Ipc +| - HallKierAlpha +| - Kappa1 - Kappa3 +| - Chi0, Chi1 +| - Chi0n - Chi4n +| - Chi0v - Chi4v +| - FormalCharge +| - MolLogP +| - MolMR +| - MolWt +| - HeavyAtomCount +| - HeavyAtomMolWt +| - NHOHCount +| - NOCount +| - NumHAcceptors +| - NumHDonors +| - NumHeteroatoms +| - NumRotatableBonds +| - NumValenceElectrons +| - RingCount +| - SSSR +| - TPSA +| - LabuteASA +| - PEOE_VSA1 - PEOE_VSA14 +| - SMR_VSA1 - SMR_VSA10 +| - SlogP_VSA1 - SlogP_VSA12 +| - EState_VSA1 - EState_VSA11 +| - VSA_EState1 - VSA_EState10 +| - Topliss fragments | | A full list of the descriptors can be obtained here_. @@ -119,7 +306,7 @@ **Hint** -Use the **cut columns from a table** tool to select just the desired descriptors. +Use the **cut columns from a table** tool to select just the desired descriptors. Alternatively, if you just want to calculate a subset of the descriptors, there is an option available to do so. ----- @@ -130,6 +317,8 @@ | - `SDF Format`_ | - `SMILES Format`_ | - `Corina MOL2`_ +| - PDB +| - InChi .. _SDF Format: http://en.wikipedia.org/wiki/Chemical_table_file .. _SMILES Format: http://en.wikipedia.org/wiki/Simplified_molecular_input_line_entry_specification
--- a/sdf_to_tab.py Tue Jul 28 08:43:19 2020 -0400 +++ b/sdf_to_tab.py Wed Feb 17 12:59:43 2021 +0000 @@ -1,8 +1,10 @@ #!/usr/bin/env python3 import argparse + import pandas as pd from rdkit import Chem + def sdf_to_tab(vars): mols = Chem.SDMolSupplier(vars.inp, sanitize=False) df = pd.DataFrame() # for output @@ -29,6 +31,7 @@ sorted_cols = sorted(df.columns.values.tolist()) df.to_csv(vars.out, sep='\t', header=vars.header, columns=sorted_cols) + def main(): parser = argparse.ArgumentParser(description="Convert SDF to tabular") parser.add_argument('--inp', '-i', help="The input file", required=True) @@ -41,7 +44,7 @@ parser.add_argument('--name', '-n', action='store_true', help="Include molecule name in output.") sdf_to_tab(parser.parse_args()) - + if __name__ == "__main__": main()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/mol.pdb Wed Feb 17 12:59:43 2021 +0000 @@ -0,0 +1,72 @@ +COMPND CNCC(O)CCCc1ccccc1 +AUTHOR GENERATED BY OPEN BABEL 3.1.0 +HETATM 1 C UNL 1 9.206 6.617 23.375 1.00 0.00 C +HETATM 2 N UNL 1 9.288 5.239 22.843 1.00 0.00 N1+ +HETATM 3 C UNL 1 9.901 4.245 23.787 1.00 0.00 C +HETATM 4 C UNL 1 9.552 2.837 23.275 1.00 0.00 C +HETATM 5 O UNL 1 10.280 2.666 22.057 1.00 0.00 O +HETATM 6 C UNL 1 9.877 1.780 24.331 1.00 0.00 C +HETATM 7 C UNL 1 9.398 0.387 23.922 1.00 0.00 C +HETATM 8 C UNL 1 10.424 -0.687 24.293 1.00 0.00 C +HETATM 9 C UNL 1 11.616 -0.605 23.380 1.00 0.00 C +HETATM 10 C UNL 1 11.773 -1.516 22.327 1.00 0.00 C +HETATM 11 C UNL 1 12.918 -1.487 21.533 1.00 0.00 C +HETATM 12 C UNL 1 13.916 -0.552 21.786 1.00 0.00 C +HETATM 13 C UNL 1 13.767 0.367 22.824 1.00 0.00 C +HETATM 14 C UNL 1 12.623 0.342 23.620 1.00 0.00 C +HETATM 15 H UNL 1 8.759 7.256 22.643 1.00 0.00 H +HETATM 16 H UNL 1 10.189 6.970 23.605 1.00 0.00 H +HETATM 17 H UNL 1 8.609 6.620 24.264 1.00 0.00 H +HETATM 18 H UNL 1 9.849 5.259 21.991 1.00 0.00 H +HETATM 19 H UNL 1 8.329 4.932 22.679 1.00 0.00 H +HETATM 20 H UNL 1 9.504 4.384 24.771 1.00 0.00 H +HETATM 21 H UNL 1 10.962 4.375 23.832 1.00 0.00 H +HETATM 22 H UNL 1 8.505 2.722 23.087 1.00 0.00 H +HETATM 23 H UNL 1 11.228 2.771 22.229 1.00 0.00 H +HETATM 24 H UNL 1 9.401 2.052 25.249 1.00 0.00 H +HETATM 25 H UNL 1 10.941 1.741 24.440 1.00 0.00 H +HETATM 26 H UNL 1 9.242 0.370 22.864 1.00 0.00 H +HETATM 27 H UNL 1 8.487 0.178 24.443 1.00 0.00 H +HETATM 28 H UNL 1 9.974 -1.653 24.199 1.00 0.00 H +HETATM 29 H UNL 1 10.746 -0.530 25.301 1.00 0.00 H +HETATM 30 H UNL 1 11.037 -2.214 22.138 1.00 0.00 H +HETATM 31 H UNL 1 13.025 -2.159 20.758 1.00 0.00 H +HETATM 32 H UNL 1 14.769 -0.538 21.204 1.00 0.00 H +HETATM 33 H UNL 1 14.504 1.066 23.003 1.00 0.00 H +HETATM 34 H UNL 1 12.517 1.022 24.389 1.00 0.00 H +CONECT 1 2 15 16 17 +CONECT 2 1 3 18 19 +CONECT 3 2 4 20 21 +CONECT 4 3 5 6 22 +CONECT 5 4 23 +CONECT 6 4 7 24 25 +CONECT 7 6 8 26 27 +CONECT 8 7 9 28 29 +CONECT 9 8 10 10 14 +CONECT 10 9 9 11 30 +CONECT 11 10 12 12 31 +CONECT 12 11 11 13 32 +CONECT 13 12 14 14 33 +CONECT 14 9 13 13 34 +CONECT 15 1 +CONECT 16 1 +CONECT 17 1 +CONECT 18 2 +CONECT 19 2 +CONECT 20 3 +CONECT 21 3 +CONECT 22 4 +CONECT 23 5 +CONECT 24 6 +CONECT 25 6 +CONECT 26 7 +CONECT 27 7 +CONECT 28 8 +CONECT 29 8 +CONECT 30 10 +CONECT 31 11 +CONECT 32 12 +CONECT 33 13 +CONECT 34 14 +MASTER 0 0 0 0 0 0 0 0 34 0 34 0 +END
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/mol_pdb_charges.tab Wed Feb 17 12:59:43 2021 +0000 @@ -0,0 +1,1 @@ +CNCC(O)CCCc1ccccc1 1
--- a/test-data/rdkit_descriptors_result1.tab Tue Jul 28 08:43:19 2020 -0400 +++ b/test-data/rdkit_descriptors_result1.tab Wed Feb 17 12:59:43 2021 +0000 @@ -1,2 +1,2 @@ -MoleculeID BalabanJ BertzCT Chi0 Chi0n Chi0v Chi1 Chi1n Chi1v Chi2n Chi2v Chi3n Chi3v Chi4n Chi4v EState_VSA1 EState_VSA10 EState_VSA11 EState_VSA2 EState_VSA3 EState_VSA4 EState_VSA5 EState_VSA6 EState_VSA7 EState_VSA8 EState_VSA9 ExactMolWt FpDensityMorgan1 FpDensityMorgan2 FpDensityMorgan3 FractionCSP3 HallKierAlpha HeavyAtomCount HeavyAtomMolWt Ipc Kappa1 Kappa2 Kappa3 LabuteASA MaxAbsEStateIndex MaxAbsPartialCharge MaxEStateIndex MaxPartialCharge MinAbsEStateIndex MinAbsPartialCharge MinEStateIndex MinPartialCharge MolLogP MolMR MolWt NHOHCount NOCount NumAliphaticCarbocycles NumAliphaticHeterocycles NumAliphaticRings NumAromaticCarbocycles NumAromaticHeterocycles NumAromaticRings NumHAcceptors NumHDonors NumHeteroatoms NumRadicalElectrons NumRotatableBonds NumSaturatedCarbocycles NumSaturatedHeterocycles NumSaturatedRings NumValenceElectrons PEOE_VSA1 PEOE_VSA10 PEOE_VSA11 PEOE_VSA12 PEOE_VSA13 PEOE_VSA14 PEOE_VSA2 PEOE_VSA3 PEOE_VSA4 PEOE_VSA5 PEOE_VSA6 PEOE_VSA7 PEOE_VSA8 PEOE_VSA9 RingCount SMR_VSA1 SMR_VSA10 SMR_VSA2 SMR_VSA3 SMR_VSA4 SMR_VSA5 SMR_VSA6 SMR_VSA7 SMR_VSA8 SMR_VSA9 SlogP_VSA1 SlogP_VSA10 SlogP_VSA11 SlogP_VSA12 SlogP_VSA2 SlogP_VSA3 SlogP_VSA4 SlogP_VSA5 SlogP_VSA6 SlogP_VSA7 SlogP_VSA8 SlogP_VSA9 TPSA VSA_EState1 VSA_EState10 VSA_EState2 VSA_EState3 VSA_EState4 VSA_EState5 VSA_EState6 VSA_EState7 VSA_EState8 VSA_EState9 fr_Al_COO fr_Al_OH fr_Al_OH_noTert fr_ArN fr_Ar_COO fr_Ar_N fr_Ar_NH fr_Ar_OH fr_COO fr_COO2 fr_C_O fr_C_O_noCOO fr_C_S fr_HOCCN fr_Imine fr_NH0 fr_NH1 fr_NH2 fr_N_O fr_Ndealkylation1 fr_Ndealkylation2 fr_Nhpyrrole fr_SH fr_aldehyde fr_alkyl_carbamate fr_alkyl_halide fr_allylic_oxid fr_amide fr_amidine fr_aniline fr_aryl_methyl fr_azide fr_azo fr_barbitur fr_benzene fr_benzodiazepine fr_bicyclic fr_diazo fr_dihydropyridine fr_epoxide fr_ester fr_ether fr_furan fr_guanido fr_halogen fr_hdrzine fr_hdrzone fr_imidazole fr_imide fr_isocyan fr_isothiocyan fr_ketone fr_ketone_Topliss fr_lactam fr_lactone fr_methoxy fr_morpholine fr_nitrile fr_nitro fr_nitro_arom fr_nitro_arom_nonortho fr_nitroso fr_oxazole fr_oxime fr_para_hydroxylation fr_phenol fr_phenol_noOrthoHbond fr_phos_acid fr_phos_ester fr_piperdine fr_piperzine fr_priamide fr_prisulfonamd fr_pyridine fr_quatN fr_sulfide fr_sulfonamd fr_sulfone fr_term_acetylene fr_tetrazole fr_thiazole fr_thiocyan fr_thiophene fr_unbrch_alkane fr_urea qed -3037 2.370228 503.61088 12.413849 8.821565 10.333422 8.058551 5.008353 5.764282 3.722845 4.595717 2.463985 2.934179 1.596526 1.985926 0.0 10.213055 0.0 11.499024 27.592991 0.0 12.132734 24.265468 0.0 0.0 23.20188 268.005785 0.764706 1.176471 1.588235 0.076923 -1.38 17 259.047 6943.4452 12.086867 4.861181 2.842672 109.048439 9.683208 0.507662 9.683208 0.118709 0.147014 0.118709 0.147014 -0.507662 3.9954 69.0396 269.127 2 2 0 0 0 2 0 2 2 2 4 0 2 0 0 0 88 10.213055 11.499024 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 23.20188 47.525105 16.466088 0.0 2 10.213055 23.20188 0.0 0.0 0.0 6.420822 0.0 57.570372 0.0 11.499024 0.0 0.0 11.499024 23.20188 10.213055 6.420822 0.0 11.126903 36.398202 10.045267 0.0 0.0 40.46 0.0 11.70887 0.0 20.448487 1.29642 0.294029 9.600621 0.373796 0.0 0.0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.864713 +MoleculeID BalabanJ BertzCT Chi0 Chi0n Chi0v Chi1 Chi1n Chi1v Chi2n Chi2v Chi3n Chi3v Chi4n Chi4v EState_VSA1 EState_VSA10 EState_VSA11 EState_VSA2 EState_VSA3 EState_VSA4 EState_VSA5 EState_VSA6 EState_VSA7 EState_VSA8 EState_VSA9 ExactMolWt FormalCharge FpDensityMorgan1 FpDensityMorgan2 FpDensityMorgan3 FractionCSP3 HallKierAlpha HeavyAtomCount HeavyAtomMolWt Ipc Kappa1 Kappa2 Kappa3 LabuteASA MaxAbsEStateIndex MaxAbsPartialCharge MaxEStateIndex MaxPartialCharge MinAbsEStateIndex MinAbsPartialCharge MinEStateIndex MinPartialCharge MolLogP MolMR MolWt NHOHCount NOCount NumAliphaticCarbocycles NumAliphaticHeterocycles NumAliphaticRings NumAromaticCarbocycles NumAromaticHeterocycles NumAromaticRings NumHAcceptors NumHDonors NumHeteroatoms NumRadicalElectrons NumRotatableBonds NumSaturatedCarbocycles NumSaturatedHeterocycles NumSaturatedRings NumValenceElectrons PEOE_VSA1 PEOE_VSA10 PEOE_VSA11 PEOE_VSA12 PEOE_VSA13 PEOE_VSA14 PEOE_VSA2 PEOE_VSA3 PEOE_VSA4 PEOE_VSA5 PEOE_VSA6 PEOE_VSA7 PEOE_VSA8 PEOE_VSA9 RingCount SMR_VSA1 SMR_VSA10 SMR_VSA2 SMR_VSA3 SMR_VSA4 SMR_VSA5 SMR_VSA6 SMR_VSA7 SMR_VSA8 SMR_VSA9 SSSR SlogP_VSA1 SlogP_VSA10 SlogP_VSA11 SlogP_VSA12 SlogP_VSA2 SlogP_VSA3 SlogP_VSA4 SlogP_VSA5 SlogP_VSA6 SlogP_VSA7 SlogP_VSA8 SlogP_VSA9 TPSA VSA_EState1 VSA_EState10 VSA_EState2 VSA_EState3 VSA_EState4 VSA_EState5 VSA_EState6 VSA_EState7 VSA_EState8 VSA_EState9 fr_Al_COO fr_Al_OH fr_Al_OH_noTert fr_ArN fr_Ar_COO fr_Ar_N fr_Ar_NH fr_Ar_OH fr_COO fr_COO2 fr_C_O fr_C_O_noCOO fr_C_S fr_HOCCN fr_Imine fr_NH0 fr_NH1 fr_NH2 fr_N_O fr_Ndealkylation1 fr_Ndealkylation2 fr_Nhpyrrole fr_SH fr_aldehyde fr_alkyl_carbamate fr_alkyl_halide fr_allylic_oxid fr_amide fr_amidine fr_aniline fr_aryl_methyl fr_azide fr_azo fr_barbitur fr_benzene fr_benzodiazepine fr_bicyclic fr_diazo fr_dihydropyridine fr_epoxide fr_ester fr_ether fr_furan fr_guanido fr_halogen fr_hdrzine fr_hdrzone fr_imidazole fr_imide fr_isocyan fr_isothiocyan fr_ketone fr_ketone_Topliss fr_lactam fr_lactone fr_methoxy fr_morpholine fr_nitrile fr_nitro fr_nitro_arom fr_nitro_arom_nonortho fr_nitroso fr_oxazole fr_oxime fr_para_hydroxylation fr_phenol fr_phenol_noOrthoHbond fr_phos_acid fr_phos_ester fr_piperdine fr_piperzine fr_priamide fr_prisulfonamd fr_pyridine fr_quatN fr_sulfide fr_sulfonamd fr_sulfone fr_term_acetylene fr_tetrazole fr_thiazole fr_thiocyan fr_thiophene fr_unbrch_alkane fr_urea qed +3037 2.370228 503.61088 12.413849 8.821565 10.333422 8.058551 5.008353 5.764282 3.722845 4.595717 2.463985 2.934179 1.596526 1.985926 0.0 10.213055 0.0 11.499024 27.592991 0.0 12.132734 24.265468 0.0 0.0 23.20188 268.005785 0 0.764706 1.176471 1.588235 0.076923 -1.38 17 259.047 6943.4452 12.086867 4.861181 2.842672 109.048439 9.683208 0.507662 9.683208 0.118709 0.147014 0.118709 0.147014 -0.507662 3.9954 69.0396 269.127 2 2 0 0 0 2 0 2 2 2 4 0 2 0 0 0 88 10.213055 11.499024 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 23.20188 47.525105 16.466088 0.0 2 10.213055 23.20188 0.0 0.0 0.0 6.420822 0.0 57.570372 0.0 11.499024 2 0.0 0.0 11.499024 23.20188 10.213055 6.420822 0.0 11.126903 36.398202 10.045267 0.0 0.0 40.46 0.0 11.70887 0.0 20.448487 1.29642 0.294029 9.600621 0.373796 0.0 0.0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.864713