|
| 1 | +//! # Properties |
| 2 | +//! |
| 3 | +//! Contains chemical properties for species in the simulation. |
| 4 | +
|
| 5 | +extern crate uom; |
| 6 | +extern crate pubchem; |
| 7 | +///Importing pure species properties |
| 8 | +pub mod pure_species_properties; |
| 9 | + |
| 10 | +use anyhow::Result; |
| 11 | +use uom::si::f64::*; |
| 12 | +use std::{thread,time::Duration}; |
| 13 | +use serde::{Serialize, Deserialize}; |
| 14 | + |
| 15 | +#[allow(dead_code)] |
| 16 | +/// Used by the "Chemical" struct to create the pubchem::Compound obj based on |
| 17 | +/// either the chemical name or the pubchem id of the chemical |
| 18 | +pub enum ChemicalIdentifier { |
| 19 | + /// The PubChem ID of the component. |
| 20 | + PubchemID(u32), |
| 21 | + /// The actual name of the component. |
| 22 | + CompoundName(String), |
| 23 | +} |
| 24 | + |
| 25 | + |
| 26 | +#[allow(dead_code)] |
| 27 | +/// A struct to store information regarding the chemical properties of a |
| 28 | +/// particular substance. The "Chemical" struct is a wrapper for the |
| 29 | +/// pubchem::Compound object |
| 30 | +pub struct Chemical { |
| 31 | + /// The (PubChem)[<https://pubchem.ncbi.nlm.nih.gov/>] CID of a compound. |
| 32 | + pub pubchem_obj: pubchem::Compound, |
| 33 | + /// Physical properties of a compound. |
| 34 | + pub properties: ChemicalProperties, |
| 35 | +} |
| 36 | + |
| 37 | +#[allow(dead_code)] |
| 38 | +/// Implementation of the chemical of interest. |
| 39 | +impl Chemical { |
| 40 | + /// Constructs a new chemical. |
| 41 | + pub fn new(identifier: ChemicalIdentifier) -> Result<Self> { |
| 42 | + let pubchem_chemical_object = match identifier { |
| 43 | + ChemicalIdentifier::PubchemID(id) => pubchem::Compound::new(id), |
| 44 | + ChemicalIdentifier::CompoundName(name) => pubchem::Compound::with_name(name.as_str()), |
| 45 | + }; |
| 46 | + let mut request_counter = 0; |
| 47 | + let mut cid_vec = None; |
| 48 | + while request_counter <= 10 { |
| 49 | + match pubchem_chemical_object.cids(){ |
| 50 | + Ok(cid_list) => { |
| 51 | + cid_vec = Some(cid_list); |
| 52 | + break; |
| 53 | + }, |
| 54 | + _ => { |
| 55 | + request_counter += 1; |
| 56 | + thread::sleep(Duration::from_secs(10)); |
| 57 | + } |
| 58 | + }; |
| 59 | + } |
| 60 | + |
| 61 | + // let cid_vec = pubchem_chemical_object.cids().unwrap(); |
| 62 | + let cid: i32 = cid_vec.unwrap()[0]; |
| 63 | + let prop = ChemicalProperties::new(cid).unwrap(); |
| 64 | + Ok(Chemical { |
| 65 | + pubchem_obj: pubchem_chemical_object, |
| 66 | + properties: prop, |
| 67 | + }) |
| 68 | + } |
| 69 | + /// Returns the pubchem object for the compound. |
| 70 | + pub fn get_pubchem_obj(&self) -> &pubchem::Compound { |
| 71 | + &self.pubchem_obj |
| 72 | + } |
| 73 | + |
| 74 | + /// Returns the "ChemicalProperties" object for the "Chemical" object. |
| 75 | + pub fn get_properties(&self) -> &ChemicalProperties { |
| 76 | + &self.properties |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +#[allow(dead_code)] |
| 81 | +/// Struct containing properties of a chemical |
| 82 | +pub struct ChemicalProperties { |
| 83 | + /// Pure species properties |
| 84 | + pub critical: Option<CriticalProperties>, |
| 85 | + |
| 86 | + /// Heat capacity coefficients (optional, stored as an array) |
| 87 | + pub heat_capacity: Option<HeatCapacityCoefficients>, |
| 88 | + |
| 89 | + /// Transport properties (optional, could include viscosity, etc.) |
| 90 | + pub transport: Option<TransportProperties>, |
| 91 | + |
| 92 | + /// Additional chemical property categories |
| 93 | + // Here we might add properties related to binary interactions, etc... |
| 94 | + pub other_properties: Option<Vec<OtherProperty>>, |
| 95 | +} |
| 96 | + |
| 97 | +/// Trait to group all property libraries |
| 98 | +trait PropertyLibrary { |
| 99 | + /// default function for connecting the database to pull relevant property information |
| 100 | + fn oscps_db_connection(&self) -> &db_connection; |
| 101 | +} |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +#[cfg(test)] |
| 106 | +mod chemical_species_tests { |
| 107 | +} |
0 commit comments