pubchem.rs
Rust data structures and client for the PubChem REST API.
Create a Compound
to query the PubChem API for a single compound. It can
be constructed from a compound ID, from a compound name, from an InChI or
InChIKey, or from a SMILES string:
```rust extern crate pubchem;
let alanine = pubchem::Compound::new(5950); let aspirin = pubchem::Compound::withname("aspirin"); let acetone = pubchem::Compound::withinchi("InChI=1S/C3H6O/c1-3(2)4/h1-2H3"); let lysine = pubchem::Compound::withinchikey("KDXKERNSBIXSRK-YFKPBYRVSA-N"); let benzene = pubchem::Compound::withsmiles("C1=CC=CC=C1"); ```
Use the methods to query the REST API with ureq
.
Dedicated methods exist for common single properties:
```rust let alanine = pubchem::Compound::new(5950);
alanine.title().unwrap(); // "Alanine" alanine.molecularformula().unwrap(); // "C3H7NO2" alanine.canonicalsmiles().unwrap(); // "CC(C(=O)O)N" alanine.isomeric_smiles().unwrap(); // "CC@@HN" ```
Each method will perform a single query to the PubChem API, which is inefficient
if you wish to retrieve several properties at once. In that case, use the
properties
method and select which properties you want to retrieve
in a single query:
```rust use pubchem::CompoundProperty::*;
let properties = pubchem::Compound::new(5950) .properties(&[Title, MolecularFormula, CanonicalSMILES]) .unwrap();
properties.molecularformula; // Some("C3H7NO2") properties.canonicalsmiles; // Some("CC(C(=O)O)N") properties.isomeric_smiles; // Some("CC@@HN") ```
Found a bug ? Have an enhancement request ? Head over to the GitHub issue tracker if you need to report or ask something. If you are filing in on a bug, please include as much information as you can about the issue, and try to recreate the same bug in a simple, easily reproducible situation.
This project adheres to Semantic Versioning and provides a changelog in the Keep a Changelog format.
If you're a bioinformatician and a Rustacean, you may be interested in these other libraries:
uniprot.rs
: Rust data structures
for the UniProtKB databases.obofoundry.rs
: Rust data
structures for the OBO Foundry.fastobo
: Rust parser and abstract
syntax tree for Open Biomedical Ontologies.This library is provided under the open-source MIT license.
This project is in no way not affiliated, sponsored, or otherwise endorsed by the PubChem developers. It was developed by Martin Larralde during his PhD project at the European Molecular Biology Laboratory in the Zeller team.