def main(): # Example usage # python -m pipelines.xchem.featurestein_score -i ../../data/mpro/poses.sdf.gz -f mpro-fstein.p -o fstein global fmaps parser = argparse.ArgumentParser(description='FeatureStein scoring with RDKit') parameter_utils.add_default_io_args(parser) parser.add_argument('-f', '--feat-map', help='Feature Map pickle to score with') parser.add_argument('--no-gzip', action='store_true', help='Do not compress the output (STDOUT is never compressed') parser.add_argument('--metrics', action='store_true', help='Write metrics') args = parser.parse_args() utils.log("FeatureStein Args: ", args) source = "featurestein_score.py" datasetMetaProps = {"source":source, "description": "FeatureStein scoring using RDKit " + rdBase.rdkitVersion} clsMappings = {} fieldMetaProps = [] clsMappings[field_FeatureSteinQualityScore] = "java.lang.Float" clsMappings[field_FeatureSteinQuantityScore] = "java.lang.Float" fieldMetaProps.append({"fieldName":field_FeatureSteinQualityScore, "values": {"source":source, "description":"FeatureStein quality score"}, "fieldName":field_FeatureSteinQuantityScore, "values": {"source":source, "description":"FeatureStein quantity score"}}) pkl_file = open(args.feat_map, 'rb') fmaps = pickle.load(pkl_file) utils.log('FeatureMap has', fmaps.GetNumFeatures(), "features") inputs_file, inputs_supplr = rdkit_utils.default_open_input(args.input, args.informat) output, writer, output_base = rdkit_utils.default_open_output(args.output, 'featurestein', args.outformat, valueClassMappings=clsMappings, datasetMetaProps=datasetMetaProps, fieldMetaProps=fieldMetaProps, compress=not args.no_gzip) # this does the processing total, success, errors = process(inputs_supplr, writer) inputs_file.close() writer.flush() writer.close() output.close() if args.metrics: utils.write_metrics(output_base, {'__InputCount__':total, '__OutputCount__':success, '__ErrorCount__':errors, 'RDKitFeatureMap':success})
def main(): # Example usage: # python -m pipelines.xchem.xcos -f ../../data/mpro/hits-17.sdf.gz -i ../../data/mpro/poses.sdf.gz -o xcos parser = argparse.ArgumentParser(description='XCos scoring with RDKit') parameter_utils.add_default_io_args(parser) parser.add_argument('-f', '--fragments', required=True, help='Fragments to compare') parser.add_argument('-ff', '--fragments-format', help='Fragments format') parser.add_argument('-t', '--score-threshold', type=float, default=0.4, help='Minimum shape overlay and feature map score required for scoring a bit to a fragment') parser.add_argument('--no-gzip', action='store_true', help='Do not compress the output (STDOUT is never compressed') parser.add_argument('--metrics', action='store_true', help='Write metrics') args = parser.parse_args() utils.log("XCos Args: ", args) source = "xcos.py" datasetMetaProps = {"source":source, "description": "XCos scoring using RDKit " + rdBase.rdkitVersion} clsMappings = {} fieldMetaProps = [] clsMappings[field_XCosRefMols] = "java.lang.String" clsMappings[field_XCosNumHits] = "java.lang.Integer" clsMappings[field_XCosScore1] = "java.lang.Float" fieldMetaProps.append({"fieldName":field_XCosRefMols, "values": {"source":source, "description":"XCos reference fragments"}}) fieldMetaProps.append({"fieldName":field_XCosNumHits, "values": {"source":source, "description":"XCos number of hits"}}) fieldMetaProps.append({"fieldName":field_XCosScore1, "values": {"source":source, "description":"XCos score 1"}}) frags_input,frags_suppl = rdkit_utils.default_open_input(args.fragments, args.fragments_format) inputs_file, inputs_supplr = rdkit_utils.default_open_input(args.input, args.informat) output, writer, output_base = rdkit_utils.default_open_output(args.output, 'xcos', args.outformat, valueClassMappings=clsMappings, datasetMetaProps=datasetMetaProps, fieldMetaProps=fieldMetaProps, compress=not args.no_gzip) # this does the processing process(inputs_supplr, frags_suppl, writer, threshold=args.score_threshold) writer.close()
def main(): # Example usage # python -m pipelines.xchem.rmsd_filter -i ../../data/mpro/poses.sdf.gz -o output -c 0.5 parser = argparse.ArgumentParser(description='RSMD filter') parameter_utils.add_default_io_args(parser) parser.add_argument('-c', '--cutoff-rmsd', type=float, help='RMSD cutoff') parser.add_argument('-f', '--field', default='_Name', help='Field to group records') parser.add_argument( '--no-gzip', action='store_true', help='Do not compress the output (STDOUT is never compressed') parser.add_argument('--metrics', action='store_true', help='Write metrics') args = parser.parse_args() utils.log("RSMD filter Args: ", args) source = "rmsd_filter.py" datasetMetaProps = { "source": source, "description": "RMSD filter " + rdBase.rdkitVersion } clsMappings = {} fieldMetaProps = [] # clsMappings[field_FeatureSteinQualityScore] = "java.lang.Float" # clsMappings[field_FeatureSteinQuantityScore] = "java.lang.Float" # fieldMetaProps.append({"fieldName":field_FeatureSteinQualityScore, "values": {"source":source, "description":"FeatureStein quality score"}, # "fieldName":field_FeatureSteinQuantityScore, "values": {"source":source, "description":"FeatureStein quantity score"}}) inputs_file, inputs_supplr = rdkit_utils.default_open_input( args.input, args.informat) output, writer, output_base = rdkit_utils.default_open_output( args.output, 'rmsd_filter', args.outformat, valueClassMappings=clsMappings, datasetMetaProps=datasetMetaProps, fieldMetaProps=fieldMetaProps, compress=not args.no_gzip) # this does the processing count, groups, kept, errors = process(inputs_supplr, writer, args.field, args.cutoff_rmsd) utils.log('Processing complete.', count, 'records processed with', groups, 'groups.', kept, 'records retained.', errors, 'errors') inputs_file.close() writer.flush() writer.close() output.close() if args.metrics: utils.write_metrics( output_base, { '__InputCount__': total, '__OutputCount__': success, '__ErrorCount__': errors, 'RDKitFeatureMap': success })
def main(): ### command line args definitions ######################################### parser = argparse.ArgumentParser(description='Filter interactions') parameter_utils.add_default_io_args(parser) parser.add_argument('-f', '--group-by-field', required=True, help='Field to group records by (must be sequential)') parser.add_argument('-s', '--score-field', required=True, help='Field to use to rank records within a group') parser.add_argument('-d', '--score-descending', action='store_true', help='Sort records in descending order') parser.add_argument('-x', '--stats-fields', nargs='*', help='Field to use to for summary statistics') parser.add_argument('-q', '--quiet', action='store_true', help='Quiet mode') parser.add_argument('--thin', action='store_true', help='Thin output mode') parser.add_argument( '--no-gzip', action='store_true', help='Do not compress the output (STDOUT is never compressed') args = parser.parse_args() utils.log("filter_interactions: ", args) # handle metadata source = "filter_interactions.py" datasetMetaProps = { "source": source, "description": "Filter by interactions" } clsMappings = { # "EnumChargesSrcMolUUID": "java.lang.String", # "EnumChargesSrcMolIdx": "java.lang.Integer" } fieldMetaProps = [ # {"fieldName": "EnumChargesSrcMolUUID", "values": {"source": source, "description": "UUID of source molecule"}}, # {"fieldName": "EnumChargesSrcMolIdx", "values": {"source": source, "description": "Index of source molecule"}} ] input, suppl = rdkit_utils.default_open_input(args.input, args.informat) output, writer, output_base = rdkit_utils.default_open_output( args.output, 'filter_interactions', args.outformat, thinOutput=False, valueClassMappings=clsMappings, datasetMetaProps=datasetMetaProps, fieldMetaProps=fieldMetaProps, compress=not args.no_gzip) report_file = open(output_base + '.report', 'wt') count, total, errors = execute(suppl, writer, report_file, args.group_by_field, args.score_field, args.score_descending, args.stats_fields) utils.log(count, total, errors) if input: input.close() writer.flush() writer.close() output.close() report_file.close() # re-write the metadata as we now know the size if args.outformat == 'json': utils.write_squonk_datasetmetadata(output_base, False, clsMappings, datasetMetaProps, fieldMetaProps, size=total) if args.meta: utils.write_metrics( output_base, { '__InputCount__': count, '__OutputCount__': total, '__ErrorCount__': errors, 'FilterInteractions': total })
def main(): ### command line args defintions ######################################### ### Define the reactions available poised_filter = True if poised_filter == True: from poised_filter import Filter filter_to_use = Filter() parser = argparse.ArgumentParser(description='RDKit rxn process') parameter_utils.add_default_io_args(parser) parser.add_argument('-q', '--quiet', action='store_true', help='Quiet mode') parser.add_argument('-m', '--multi', action='store_true', help='Output one file for each reaction') parser.add_argument('-r', '--reaction', choices=filter_to_use.poised_reactions.keys(), help='Name of reaction to be run') parser.add_argument('-rl', '--reagent_lib', help="Input SD file, if not defined the STDIN is used") parser.add_argument( '-rlf', '--reagent_lib_format', choices=['sdf', 'json'], help="Input format. When using STDIN this must be specified.") args = parser.parse_args() utils.log("Screen Args: ", args) if not args.output and args.multi: raise ValueError( "Must specify output location when writing individual result files" ) input, suppl = rdkit_utils.default_open_input(args.input, args.informat) reagent_input, reagent_suppl = rdkit_utils.default_open_input( args.reagent_lib, args.reagent_lib_format) output, writer, output_base = rdkit_utils.default_open_output( args.output, "rxn_maker", args.outformat) i = 0 count = 0 if args.multi: dir_base = os.path.dirname(args.output) writer_dict = filter_to_use.get_writers(dir_base) else: writer_dict = None dir_base = None for mol in suppl: i += 1 if mol is None: continue # Return a dict/class here - indicating which filters passed count = filter_to_use.perform_reaction(mol, args.reaction, reagent_suppl, writer, count) utils.log("Created", count, "molecules from a total of ", i, "input molecules") writer.flush() writer.close() if input: input.close() if output: output.close() # close the individual writers if writer_dict: for key in writer_dict: writer_dict[key].close() if args.meta: utils.write_metrics( output_base, { '__InputCount__': i, '__OutputCount__': count, 'RxnSmartsFilter': count })
def main(): global PDB_PATH, WRITER, THRESHOLD parser = argparse.ArgumentParser( description='PLI scoring - Docking calculation.') parameter_utils.add_default_io_args(parser) parser.add_argument( '--no-gzip', action='store_true', help='Do not compress the output (STDOUT is never compressed') parser.add_argument('-pdb', '--pdb_file', help="PDB file for scoring") parser.add_argument('-t', '--threshold', type=float, help="The maximum score to allow", default=None) parser.add_argument( '--threads', type=int, help="Number of threads to used. Default is the number of cores", default=None) parser.add_argument('--thin', action='store_true', help='Thin output mode') args = parser.parse_args() utils.log("PLI Args: ", args) # Open up the input file input, suppl = rdkit_utils.default_open_input(args.input, args.informat) # Open the output file s_now = datetime.datetime.utcnow().strftime("%d-%b-%Y %H:%M:%S UTC") source = 'pipelines/docking/plip.py' output, WRITER, output_base = \ rdkit_utils.default_open_output(args.output, "plip", args.outformat, compress=not args.no_gzip, thinOutput=args.thin, valueClassMappings={'pliff_iscore': 'java.lang.Float', 'pliff_cscore': 'java.lang.Float', 'pliff_nb_score': 'java.lang.Float', 'pliff_gscore': 'java.lang.Float', 'pliff_score': 'java.lang.Float', 'pliff_tscore': 'java.lang.Float'}, datasetMetaProps={'created': s_now, 'source': source, 'description': 'PLI scoring of docked structures'} ) PDB_PATH = args.pdb_file if args.threshold: THRESHOLD = args.threshold # Iterate over the molecules # WARNING - if using parallel processing the order of molecules is not preserved. Set args.threads to 1 to ensure this. pool = ThreadPool(args.threads if args. threads is not None else multiprocessing.cpu_count()) pool.map(run_dock, suppl) pool.close() pool.join() # Close the file WRITER.close() if args.meta: utils.write_metrics(output_base, { '__InputCount__': COUNTER, '__OutputCount__': SUCCESS, 'PLI': COUNTER })
def main(): # Example usage # python -m pipelines.xchem.calc_interactions -p ../../data/mpro/Mpro-x0387_0.pdb -i ../../data/mpro/hits-17.sdf.gz -o output parser = argparse.ArgumentParser(description='Calculate interactions') parameter_utils.add_default_io_args(parser) parser.add_argument('-p', '--protein', nargs='*', help="File with protein (PDB or MOL2 format") # NOTE reading mol2 format seems to be problematical. parser.add_argument('-pf', '--protein-format', choices=['pdb', 'mol2'], help="Protein file format") parser.add_argument('--strict', action='store_true', help='Strict filtering') parser.add_argument( '--exact-protein', action='store_true', help='Exact matching of hydrogens and charges for protein') parser.add_argument( '--exact-ligand', action='store_true', help='Exact matching of hydrogens and charges for ligand') parser.add_argument('--keep-hs-protein', action='store_true', help='Keep hydrogens on the protein') parser.add_argument('--keep-hs-ligand', action='store_true', help='Keep hydrogens on the ligand') parser.add_argument('--key-hbond', nargs='*', help='List of canonical H-bond interactions to count') parser.add_argument( '--key-hydrophobic', nargs='*', help='List of canonical hydrophobic interactions to count') parser.add_argument( '--key-salt-bridge', nargs='*', help='List of canonical salt bridge interactions to count') parser.add_argument( '--key-pi-stacking', nargs='*', help='List of canonical pi stacking interactions to count') parser.add_argument( '--key-pi-cation', nargs='*', help='List of canonical pi cation interactions to count') parser.add_argument( '--key-halogen', nargs='*', help='List of canonical halogen bond interactions to count') parser.add_argument( '--rfscores', nargs='*', help="Pickle(s) for RFScore model e.g. RFScore_v1_pdbbind2016.pickle") parser.add_argument( '--nnscores', nargs='*', help="Pickle(s) for NNScore model e.g. NNScore_pdbbind2016.pickle") parser.add_argument( '--plecscores', nargs='*', help= "Pickle(s) for PLECScore model e.g. PLEClinear_p5_l1_pdbbind2016_s65536.pickle" ) parser.add_argument('-r', '--report-file', help="File for the report") parser.add_argument('-c', '--compare', help="Compare interactions with this report") parser.add_argument( '--no-gzip', action='store_true', help='Do not compress the output (STDOUT is never compressed') parser.add_argument('--metrics', action='store_true', help='Write metrics') args = parser.parse_args() utils.log("Calculate interactions Args: ", args) key_inters = {} if args.key_hbond: key_inters[interactions.I_TYPE_HBOND] = args.key_hbond if args.key_hydrophobic: key_inters[interactions.I_TYPE_HYDROPHOBIC] = args.key_hydrophobic if args.key_salt_bridge: key_inters[interactions.I_TYPE_SALT_BRIDGE] = args.key_salt_bridge if args.key_pi_stacking: key_inters[interactions.I_TYPE_PI_STACKING] = args.key_pi_stacking if args.key_pi_cation: key_inters[interactions.I_TYPE_PI_CATION] = args.key_pi_cation if args.key_halogen: key_inters[interactions.I_TYPE_HALOGEN] = args.key_halogen source = "calc_interactions.py using ODDT" datasetMetaProps = { "source": source, "description": "Calculate interactions using ODDT" } clsMappings = {} fieldMetaProps = [] clsMappings[interactions.I_NAME_HBOND] = "java.lang.String" clsMappings[interactions.I_NAME_HALOGEN] = "java.lang.String" clsMappings[interactions.I_NAME_HYDROPHOBIC] = "java.lang.String" clsMappings[interactions.I_NAME_SALT_BRIDGE] = "java.lang.String" clsMappings[interactions.I_NAME_PI_STACKING] = "java.lang.String" clsMappings[interactions.I_NAME_PI_CATION] = "java.lang.String" clsMappings['NumTotalInteractions'] = "java.lang.Integer" clsMappings['NumKeyInteractions'] = "java.lang.Integer" clsMappings['KeyInteractions'] = "java.lang.String" fieldMetaProps.append({ "fieldName": interactions.I_NAME_HBOND, "values": { "source": source, "description": "Hydrogen bond interactions" }, "fieldName": interactions.I_NAME_HALOGEN, "values": { "source": source, "description": "Halogen bond interactions" }, "fieldName": interactions.I_NAME_HYDROPHOBIC, "values": { "source": source, "description": "Hydrophobic interactions" }, "fieldName": interactions.I_NAME_SALT_BRIDGE, "values": { "source": source, "description": "Salt bridge interactions" }, "fieldName": interactions.I_NAME_PI_STACKING, "values": { "source": source, "description": "Pi stacking interactions" }, "fieldName": interactions.I_NAME_PI_CATION, "values": { "source": source, "description": "Pi cation interactions" } }) inputs_file, inputs_supplr = rdkit_utils.default_open_input( args.input, args.informat) output, writer, output_base = rdkit_utils.default_open_output( args.output, 'calc_interactions', args.outformat, valueClassMappings=clsMappings, datasetMetaProps=datasetMetaProps, fieldMetaProps=fieldMetaProps, compress=not args.no_gzip) # this does the processing count, errors = process(args.protein, args.input, writer, key_inters, protein_format=args.protein_format, filter_strict=args.strict, exact_protein=args.exact_protein, exact_ligand=args.exact_ligand, keep_hs_protein=args.keep_hs_protein, keep_hs_ligand=args.keep_hs_ligand, report_file=args.report_file, compare_file=args.compare, rfscores=args.rfscores, nnscores=args.nnscores, plecscores=args.plecscores) utils.log('Processing complete.', count, 'records processed.', errors, 'errors') inputs_file.close() writer.flush() writer.close() output.close() # if args.metrics: utils.write_metrics( output_base, { '__InputCount__': total, '__OutputCount__': count, '__ErrorCount__': errors, 'ODDTInteraction': count })
def main(): parser = argparse.ArgumentParser(description='Max SuCOS scores with RDKit') parameter_utils.add_default_io_args(parser) parser.add_argument('-tm', '--target-molecules', help='Target molecules to compare against') parser.add_argument('-tf', '--targets-format', help='Target molecules format') parser.add_argument('-n', '--name-field', help='Name of field with molecule name') parser.add_argument( '--no-gzip', action='store_true', help='Do not compress the output (STDOUT is never compressed') parser.add_argument('--filter-value', type=float, help='Filter out values with scores less than this.') parser.add_argument('--filter-field', help='Field to use to filter values.') args = parser.parse_args() utils.log("Max SuCOSMax Args: ", args) source = "sucos_max.py" datasetMetaProps = { "source": source, "description": "SuCOSMax using RDKit " + rdBase.rdkitVersion } clsMappings = {} fieldMetaProps = [] clsMappings[field_SuCOSMax_Score] = "java.lang.Float" clsMappings[field_SuCOSMax_FMScore] = "java.lang.Float" clsMappings[field_SuCOSMax_ProtrudeScore] = "java.lang.Float" clsMappings[field_SuCOSMax_Index] = "java.lang.Integer" clsMappings[field_SuCOSCum_Score] = "java.lang.Float" clsMappings[field_SuCOSCum_FMScore] = "java.lang.Float" clsMappings[field_SuCOSCum_ProtrudeScore] = "java.lang.Float" fieldMetaProps.append({ "fieldName": field_SuCOSMax_Score, "values": { "source": source, "description": "SuCOS Max score" } }) fieldMetaProps.append({ "fieldName": field_SuCOSMax_FMScore, "values": { "source": source, "description": "SuCOS Max Feature Map score" } }) fieldMetaProps.append({ "fieldName": field_SuCOSMax_ProtrudeScore, "values": { "source": source, "description": "SuCOS Max Protrude score" } }) fieldMetaProps.append({ "fieldName": field_SuCOSMax_Index, "values": { "source": source, "description": "SuCOS Max target index" } }) fieldMetaProps.append({ "fieldName": field_SuCOSCum_Score, "values": { "source": source, "description": "SuCOS Cumulative score" } }) fieldMetaProps.append({ "fieldName": field_SuCOSCum_FMScore, "values": { "source": source, "description": "SuCOS Cumulative Feature Map score" } }) fieldMetaProps.append({ "fieldName": field_SuCOSCum_ProtrudeScore, "values": { "source": source, "description": "SuCOS Cumulative Protrude score" } }) if args.name_field: clsMappings[field_SuCOSMax_Target] = "java.lang.String" fieldMetaProps.append({ "fieldName": field_SuCOSMax_Target, "values": { "source": source, "description": "SuCOS Max target name" } }) inputs_file, inputs_supplr = rdkit_utils.default_open_input( args.input, args.informat) output, writer, output_base = rdkit_utils.default_open_output( args.output, 'sucos-max', args.outformat, valueClassMappings=clsMappings, datasetMetaProps=datasetMetaProps, fieldMetaProps=fieldMetaProps, compress=not args.no_gzip) targets_file, targets_supplr = rdkit_utils.default_open_input( args.target_molecules, args.targets_format) count, total, errors = process(inputs_supplr, targets_supplr, writer, args.name_field, args.filter_value, args.filter_field) inputs_file.close() targets_file.close() writer.flush() writer.close() output.close() if args.meta: utils.write_metrics( output_base, { '__InputCount__': count, '__OutputCount__': total, '__ErrorCount__': errors, 'RDKitSuCOS': total })
def main(): ### command line args defintions ######################################### parser = argparse.ArgumentParser(description='RDKit filter') parser.add_argument( '-f', '--fragment', choices=['hac', 'mw'], help= 'Find single fragment if more than one (hac = biggest by heavy atom count, mw = biggest by mol weight)' ) parser.add_argument('--hacmin', type=int, help='Min heavy atom count') parser.add_argument('--hacmax', type=int, help='Max heavy atom count') parser.add_argument('--mwmin', type=float, help='Min mol weight') parser.add_argument('--mwmax', type=float, help='Max mol weight') parser.add_argument('--rotbmin', type=float, help='Min rotatable bond count') parser.add_argument('--rotbmax', type=float, help='Max rotatable bond count') parser.add_argument('--logpmin', type=float, help='Min logP') parser.add_argument('--logpmax', type=float, help='Max logP') parser.add_argument('-l', '--limit', type=int, help='Limit output to this many records') parser.add_argument( '-c', '--chunksize', type=int, help= 'Split output into chunks of size c. Output will always be files. Names like filter1.sdf.gz, filter2.sdf.gz ...' ) parser.add_argument( '-d', '--digits', type=int, default=0, help= 'When splitting zero pad the file name to this many digits so that they are in sorted order. Names like filter001.sdf.gz, filter002.sdf.gz ...' ) parser.add_argument('-r', '--rename', action='append', help='Rename field (fromname:toname)') parser.add_argument( '-t', '--transform', action='append', help='Transform field value(fieldname:regex:type). ' + 'Regex is in the form of /regex/substitution/ (the 3 slashes are required). ' + 'Type is of int, float, boolean or string. The type is optional and if not specified then string is assumed. ' + 'Transformation occurs after field renaming so specify the new name.') parser.add_argument('--delete', action='append', help='Delete field') parser.add_argument( '--no-gzip', action='store_true', help='Do not compress the output (STDOUT is never compressed') # WARNING: thin output is not appropriate when using --fragment parser.add_argument('--thin', action='store_true', help='Thin output mode') parser.add_argument( '-q', '--quiet', action='store_true', help='Quiet mode - suppress reporting reason for filtering') parameter_utils.add_default_io_args(parser) args = parser.parse_args() utils.log("Filter Args: ", args) field_renames = {} if args.rename: for t in args.rename: parts = t.split(':') if len(parts) != 2: raise ValueError('Invalid field rename argument:', t) field_renames[parts[0]] = parts[1] if args.delete: for f in args.delete: field_renames[f] = None field_regexes = {} field_replacements = {} field_types = {} if args.transform: for t in args.transform: parts = t.split(':') if len(parts) < 2 or len(parts) > 3: raise ValueError('Invalid field transform argument:', t) terms = parts[1].split('/') utils.log("|".join(terms) + str(len(terms))) field_regexes[parts[0]] = re.compile(terms[1]) field_replacements[parts[0]] = terms[2] if len(parts) == 3: t = parts[2] else: t = 'string' field_types[parts[0]] = t utils.log("Created transform of " + terms[1] + " to " + terms[2] + " using type of " + t) if args.delete: for f in args.delete: field_renames[f] = None input, suppl = rdkit_utils.default_open_input(args.input, args.informat) if args.chunksize: chunkNum = 1 if args.output: output_base = args.output else: output_base = 'filter' output_base_chunk = output_base + str(chunkNum).zfill(args.digits) output, writer, output_base_chunk = rdkit_utils.default_open_output( output_base_chunk, output_base_chunk, args.outformat, thinOutput=args.thin, compress=not args.no_gzip) else: output, writer, output_base_chunk = rdkit_utils.default_open_output( args.output, "filter", args.outformat, thinOutput=args.thin, compress=not args.no_gzip) output_base = output_base_chunk utils.log("Writing to " + output_base_chunk) i = 0 count = 0 chunkNum = 1 for mol in suppl: if args.limit and count >= args.limit: break i += 1 if mol is None: continue if args.fragment: mol = mol_utils.fragment(mol, args.fragment, quiet=args.quiet) if not filter(mol, minHac=args.hacmin, maxHac=args.hacmax, minMw=args.mwmin, maxMw=args.mwmax, minRotb=args.rotbmin, maxRotb=args.rotbmax, minLogp=args.logpmin, maxLogp=args.logpmax, quiet=args.quiet): continue if args.chunksize: if count > 0 and count % args.chunksize == 0: # new chunk, so create new writer writer.close() output.close() chunkNum += 1 output_chunk_base = output_base + str(chunkNum).zfill( args.digits) utils.log("Writing to " + output_chunk_base) output, writer, output_chunk_base = rdkit_utils.default_open_output( output_chunk_base, output_chunk_base, args.outformat, thinOutput=args.thin, compress=not args.no_gzip) for from_name in field_renames: to_name = field_renames[from_name] if mol.HasProp(from_name): val = mol.GetProp(from_name) mol.ClearProp(from_name) if to_name: mol.SetProp(to_name, val) for fieldname in field_regexes: p = mol.GetProp(fieldname) if p is not None: regex = field_regexes[fieldname] q = regex.sub(field_replacements[fieldname], p) t = field_types[fieldname] if t == 'int': mol.SetIntProp(fieldname, int(q)) elif t == 'float': mol.SetDoubleProp(fieldname, float(q)) elif t == 'boolean': mol.SetBoolProp(fieldname, bool(q)) else: mol.SetProp(fieldname, q) count += 1 writer.write(mol) utils.log("Filtered", i, "down to", count, "molecules") if args.chunksize: utils.log("Wrote", chunkNum, "chunks") if (args.digits > 0 and len(str(chunkNum)) > args.digits): utils.log( "WARNING: not enough digits specified for the number of chunks" ) writer.flush() writer.close() input.close() output.close() if args.meta: utils.write_metrics(output_base, { '__InputCount__': i, '__OutputCount__': count, 'RDKitFilter': i })
def main(): ### command line args definitions ######################################### parser = argparse.ArgumentParser(description='Enumerate charges') parser.add_argument('-i', '--input', help="Input file, if not defined the STDIN is used") parser.add_argument( '-if', '--informat', choices=['sdf', 'json', 'smi'], help="Input format. When using STDIN this must be specified.") parameter_utils.add_default_output_args(parser) parser.add_argument( '--fragment-method', choices=['hac', 'mw'], help= 'Approach to find biggest fragment if more than one (hac = biggest by heavy atom count, mw = biggest by mol weight)' ) parser.add_argument( "--minimize", type=int, default=0, help="number of minimisation cycles when generating 3D molecules") parser.add_argument('--enumerate-chirals', help='Enumerate undefined chiral centers', type=int, default=0) parser.add_argument('--smiles-field', help='Add the SMILES as a field of this name') parser.add_argument( '--name-field', help= 'Use this field in the input as the name field in the output. If not specified the SMILES is used' ) parser.add_argument('--include-hydrogens', action='store_true', help='Include hydrogens in the output') parser.add_argument("--min-charge", type=int, help="Minimum charge of molecule to process") parser.add_argument("--max-charge", type=int, help="Maximum charge of molecule to process") parser.add_argument("--num-charges", type=int, help="Maximum number of atoms with a charge") parser.add_argument('-q', '--quiet', action='store_true', help='Quiet mode') parser.add_argument('--thin', action='store_true', help='Thin output mode') parser.add_argument( '--no-gzip', action='store_true', help='Do not compress the output (STDOUT is never compressed') args = parser.parse_args() utils.log("prepare_3d: ", args) # handle metadata source = "prepare_3d.py" datasetMetaProps = { "source": source, "description": "Enumerate undefined stereo isomers and generate 3D" } clsMappings = { "EnumChargesSrcMolUUID": "java.lang.String", "EnumChargesSrcMolIdx": "java.lang.Integer" } fieldMetaProps = [{ "fieldName": "EnumChargesSrcMolUUID", "values": { "source": source, "description": "UUID of source molecule" } }, { "fieldName": "EnumChargesSrcMolIdx", "values": { "source": source, "description": "Index of source molecule" } }] oformat = utils.determine_output_format(args.outformat) if args.informat == 'smi': suppl = rdkit_utils.default_open_input_smiles(args.input, delimiter='\t', titleLine=False) input = None else: input, suppl = rdkit_utils.default_open_input(args.input, args.informat) output, writer, output_base = rdkit_utils.default_open_output( args.output, 'enumerate_molecules', args.outformat, thinOutput=False, valueClassMappings=clsMappings, datasetMetaProps=datasetMetaProps, fieldMetaProps=fieldMetaProps, compress=not args.no_gzip) count, total, errors = execute(suppl, writer, minimize=args.minimize, enumerate_chirals=args.enumerate_chirals, smiles_field=args.smiles_field, include_hs=args.include_hydrogens, min_charge=args.min_charge, max_charge=args.max_charge, num_charges=args.num_charges) utils.log(count, total, errors) if input: input.close() writer.flush() writer.close() output.close() # re-write the metadata as we now know the size if oformat == 'json': utils.write_squonk_datasetmetadata(output_base, False, clsMappings, datasetMetaProps, fieldMetaProps, size=total) if args.meta: utils.write_metrics( output_base, { '__InputCount__': count, '__OutputCount__': total, '__ErrorCount__': errors, 'EnumerateChargesDimporphite': total })
def main(): # Example usage # python -m pipelines.xchem.featurestein_generate_and_score -i ../../data/mpro/poses.sdf.gz -f ../../data/mpro/hits-17.sdf.gz -o output_fs global fmaps parser = argparse.ArgumentParser( description='FeatureStein scoring with RDKit') parameter_utils.add_default_io_args(parser) parser.add_argument('-f', '--fragments', help='Fragments to use to generate the feature map') parser.add_argument('-ff', '--fragments-format', help='Fragments format') parser.add_argument( '--no-gzip', action='store_true', help='Do not compress the output (STDOUT is never compressed') parser.add_argument('--metrics', action='store_true', help='Write metrics') args = parser.parse_args() utils.log("FeatureStein Args: ", args) source = "featurestein_generate_and_score.py" datasetMetaProps = { "source": source, "description": "FeatureStein scoring using RDKit " + rdBase.rdkitVersion } clsMappings = {} fieldMetaProps = [] clsMappings[field_FeatureSteinQualityScore] = "java.lang.Float" clsMappings[field_FeatureSteinQuantityScore] = "java.lang.Float" fieldMetaProps.append({ "fieldName": field_FeatureSteinQualityScore, "values": { "source": source, "description": "FeatureStein quality score" }, "fieldName": field_FeatureSteinQuantityScore, "values": { "source": source, "description": "FeatureStein quantity score" } }) # generate the feature maps frags_input, frags_suppl = rdkit_utils.default_open_input( args.fragments, args.fragments_format) fmaps = create_featuremap(frags_suppl) frags_input.close() # read the ligands to be scored inputs_file, inputs_supplr = rdkit_utils.default_open_input( args.input, args.informat) output, writer, output_base = rdkit_utils.default_open_output( args.output, 'featurestein', args.outformat, valueClassMappings=clsMappings, datasetMetaProps=datasetMetaProps, fieldMetaProps=fieldMetaProps, compress=not args.no_gzip) # do the scoring total, success, errors = score_molecules(inputs_supplr, writer) utils.log('Scored', success, 'molecules.', errors, 'errors.') inputs_file.close() writer.flush() writer.close() output.close() if args.metrics: utils.write_metrics( output_base, { '__InputCount__': total, '__OutputCount__': success, '__ErrorCount__': errors, 'RDKitFeatureMap': success })