{"id":20504203,"url":"https://github.com/stefan-schroedl/molecule_classification","last_synced_at":"2025-09-25T07:31:44.787Z","repository":{"id":85662407,"uuid":"146048563","full_name":"stefan-schroedl/molecule_classification","owner":"stefan-schroedl","description":"\"Auto-sklearn for chemistry\" - train and run machine-learned classifiers for molecular classification tasks.","archived":false,"fork":false,"pushed_at":"2018-10-22T04:15:57.000Z","size":193,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-15T19:39:28.949Z","etag":null,"topics":["automatic","automl","cheminformatics","chemistry","chemoinformatics","hyperparameter-optimization","machine-learning","molecule","python","rdkit","scikit-learn"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stefan-schroedl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-24T23:28:13.000Z","updated_at":"2024-08-05T06:46:36.000Z","dependencies_parsed_at":"2023-03-03T22:45:29.060Z","dependency_job_id":null,"html_url":"https://github.com/stefan-schroedl/molecule_classification","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefan-schroedl%2Fmolecule_classification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefan-schroedl%2Fmolecule_classification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefan-schroedl%2Fmolecule_classification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefan-schroedl%2Fmolecule_classification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefan-schroedl","download_url":"https://codeload.github.com/stefan-schroedl/molecule_classification/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234165746,"owners_count":18789757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automatic","automl","cheminformatics","chemistry","chemoinformatics","hyperparameter-optimization","machine-learning","molecule","python","rdkit","scikit-learn"],"created_at":"2024-11-15T19:36:51.041Z","updated_at":"2025-09-25T07:31:39.489Z","avatar_url":"https://github.com/stefan-schroedl.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# molecule_classification\n\n\"[Auto-Sklearn](https://github.com/automl/auto-sklearn) for Chemistry\".\n\n## Overview\n\nTrain and run machine-learned classifiers for molecular classification tasks; for\nexample, predict properties like solubility, atomization energies, or biological\naffinities in QSAR projects.\n\nThe general purpose is to \"throw anything easily computable at the wall and see what \nsticks\". Molecules are input in the form of [SMILES](https://en.wikipedia.org/wiki/Simplified_molecular-input_line-entry_system) strings. From these, different types\nof fingerprints (fixed-sized vectors) can be computed using [RDKit](http://www.rdkit.org/). Model training is based \non classifiers based on [scikit-learn](http://scikit-learn.org/stable/) or [xgboost](https://github.com/dmlc/xgboost). More advanced representations (e.g., graph\nconvolutions) or ML models (e.g., deep neural nets) are *not* supported. However, the package\ndoes automate hyper-parameter optimization for the supported model types.\n\nThe project supplies two scripts:\n* *train_mol_class.py*: Train a scikit-learn or xgboost model\n* *predict_mol_class.py*: Generate predictions for an input file with a previously trained model\n\nPlease see the `demo` directory for a usage example.\n\n##  train_mol_class.py\n\nFor one run, a single fingerprinting method and multiple learning methods can be specified,\nwhich are applied in turn. When multiple fingerprints are specified, e.g., \n`-fpType ecfp4,prop`, their *union* is fed to the classifier. Outputs, including cross \nvalidation results, optimization results, plots, and pickled model file, are \nwritten under directory experiments/\u003cidentifier\u003e.\n\nHyper-parameter optimization by random search can be triggered by adding the suffix `_optim` \nto the classifier name. If the number of optimization iterations (`--optimIter`) exceeds 70%\nof the parameter space, the script automatically switches to exhaustive grid search. Suffix \n`_optim2` additionally finds a local minimum by optimizing each hyper-parameter individually\nand sequentially. Best parameters are stored in the output directory, and by default are \nre-used if they exist (by checking in the output directory *or* the current directory as a backup). \n\nIn general, there are many possible ways to tune the decision threshold for a classifier. In this\nproject, it is done by limiting the expected false positive rate (`-maxFPR`). This threshold is\nestimated by holding out a fraction of the training data (`--validFrac`).\n\nThere are a couple of command line parameters related to dealing with sub-categories of training\ndata; one use case is to combine a large public data set with a smaller but more important proprietary \ndata set. To increase the weight of this subset, we add an indicator column `-weightCat` in the input \ndata, and assign a higher weight using `-catToSampleWeight`. Additionally, if we are interested in the \ncross validation results *only* on the subset, we use the `-testFilterCat` option. Note that if a \n`--weightCat` is specified, cross validation is stratified with respect to it (in addition to the\ntarget column, as usual).\n\n`train_mol_class.py` uses [configargparse](https://github.com/bw2/ConfigArgParse), so all options can be supplied in a configuation file.\n\n\n```\nusage: train_mol_class.py [-h] [--config CONFIG] [--outDir DIR] [--logDir DIR]\n                          [--cacheDir DIR] --data FILE [--smilesCol SMILESCOL]\n                          --targetCol TARGETCOL [--fpType FPTYPE] [--fpSize N]\n                          [--methods METHODS] [--maxFPR MAXFPR]\n                          [--weightCat WEIGHTCAT]\n                          [--catToSampleWeight CATTOSAMPLEWEIGHT]\n                          [--testFilterCat TESTFILTERCAT] [--cv N]\n                          [--cvJobs N] [--validFrac F] [--seed N]\n                          [--resultsOverwrite N] [--optimScoring OPTIMSCORING]\n                          [--optimIter N] [--optimCV N] [--optimOverwrite N]\n                          [--optimJobs N] [--logToFile N] [--cachePipeline N]\n                          [--refit N] [--saveComment SAVECOMMENT]\n                          [--svmCacheMemFrac F] [--verbose N]\n\ntrain and evaluate a molecular classifier according to several choices of\nfingerprint and learning methods.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --config CONFIG       config file path (default: None)\n  --outDir DIR          output directory for training results (model file,\n                        cross validation and optimization metrics, plots,\n                        variable importance) (default: experiments)\n  --logDir DIR          output directory for log files (default: logs)\n  --cacheDir DIR        pipeline cache directory (default: cache)\n  --data FILE           training data, must contain a smiles and a label\n                        column (default: None)\n  --smilesCol SMILESCOL\n                        name of column containing the input smiles (default:\n                        smiles)\n  --targetCol TARGETCOL\n                        name of column containing the targets (default: None)\n  --fpType FPTYPE       type of fingerprint ['ecfp4', 'ecfp6', 'ecfp12',\n                        'maccs', 'daylight', 'ap', 'torsion', 'prop']; prop =\n                        rdkit molecular descriptors. Multiple elements mean\n                        their UNION is used, not sequentially. (default:\n                        ecfp4)\n  --fpSize N            fingerprint size (default: 2048)\n  --methods METHODS     ml methods. Note: ada and gp crash on larger data\n                        sets. Add suffix _optim to do hyperparameter\n                        optimization; _optim2 with additional stage of local\n                        optimization (changing one parameter at a time).\n                        (default: rf,gbm,lr,svm_lin,svm_poly,svm_rbf,svm_sig,n\n                        b,qda,knn1,knn10,ada,gp,dummy,xgb)\n  --maxFPR MAXFPR       false positive rate that is acceptable for threshold\n                        tuning (default: 0.2)\n  --weightCat WEIGHTCAT\n                        integer column for categories of sample weights (see\n                        catToSampleWeight). Used for cross validation\n                        stratification. (default: )\n  --catToSampleWeight CATTOSAMPLEWEIGHT\n                        mapping of categories to sample weights\n                        (cat1=w1,cat2=w2,..) (default: )\n  --testFilterCat TESTFILTERCAT\n                        use only this category for test set evaluation\n                        (default: -1)\n  --cv N                number of cross validation folds (default: 5)\n  --cvJobs N            number of cpus to use for cross validation (default:\n                        -1)\n  --validFrac F         Fraction of training data to hold out for threshold\n                        tuning (default: 0.2)\n  --seed N              random seed (default: 42)\n  --resultsOverwrite N  Overwrite previous results (default: 0)\n  --optimScoring OPTIMSCORING\n                        scoring function for hyperparameter optimization\n                        (default: average_precision)\n  --optimIter N         number of iterations for hyperparameter optimization\n                        (default: 100)\n  --optimCV N           number of CV folds for hyperparameter optimization\n                        (default: 3)\n  --optimOverwrite N    If zero and previous optimization results exists, use\n                        it (default: 1)\n  --optimJobs N         number of cpus to use for hyperparameter optimization\n                        (default: -1)\n  --logToFile N         log to file (default: 1)\n  --cachePipeline N     use cached pipelines (default: 1)\n  --refit N             refit final model on all data, save to .pkl file, and\n                        calculate variable importance (default: 0)\n  --saveComment SAVECOMMENT\n                        comment to store in refit model (default: )\n  --svmCacheMemFrac F   maximum percentage of total memory to use for svm\n                        training. Crucial for svm training speed. (default:\n                        0.5)\n  --verbose N           verbose logging [0 - no logging; 1 - info, no\n                        libraries; 2 - including libraries; 3 - debug\n                        (default: 1)\n```\n\n## predict_mol_class.py\n\nApply a trained model to a smiles file. Input can be single-or-multi-column file\nwith or without header, or can be read from stdin in a unix pipe.\n\n*Example call:*\n\n```predict_mol_class.py -m models/model_dmso.pkl.xz data/example.smi```\n\n```\nusage: predict_mol_class.py [-h] -m MODELFILE [-H N] [-d DELIMITER] [-s N]\n                            [-b N] [-D {0,1}]\n                            [PATH [PATH ...]]\n\napply a trained model to a smiles file.\n\npositional arguments:\n  PATH                  input files to score, containing smiles\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -m MODELFILE, --modelFile MODELFILE\n                        pkl file of trained model\n  -H N, --header N      does the input file contain a header line?\n  -d DELIMITER, --delimiter DELIMITER\n                        delimiter in input file\n  -s N, --smilesCol N   input column containing the smiles string\n  -b N, --batchMode N   for speed, read whole input and score in batch. To\n                        skip individual lines with invalid smiles, use 0.\n  -D {0,1}, --describeModelAndExit {0,1}\n                        only print model info without scoring\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefan-schroedl%2Fmolecule_classification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefan-schroedl%2Fmolecule_classification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefan-schroedl%2Fmolecule_classification/lists"}