Skip to content

Commit d918aa3

Browse files
Merge pull request #38 from OSCPS-Project/implement_property_modules
Implement property modules
2 parents 1134e74 + 929322a commit d918aa3

File tree

15 files changed

+275
-563
lines changed

15 files changed

+275
-563
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Generate and Deploy Rust Docs
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
rust-docs:
10+
name: Generate Rust Documentation
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Install Rust
18+
uses: dtolnay/rust-toolchain@stable
19+
20+
- name: Generate documentation
21+
run: cargo doc --no-deps
22+
23+
- name: Deploy to GitHub Pages
24+
if: github.ref == 'refs/heads/main'
25+
uses: peaceiris/actions-gh-pages@v4
26+
with:
27+
github_token: ${{ secrets.GITHUB_TOKEN }}
28+
publish_dir: ./target/doc

oscps-db/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "oscps-db"
3+
version = "0.1.0"
4+
authors = ["Nathaniel Thomas <[email protected]>", "Bhargav Akula <[email protected]>"]
5+
edition = "2021"
6+
7+
[dependencies]

oscps-db/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
///#OSCPS-db
2+
///
3+
///Main library folder for the OSCPS-db library crate
4+
///
5+
///will hold the methods to pull information from the POSTGRES database and from relevant APIs
6+
///
7+
///Will hold property information for chemcial property calculation
8+
///Will hold information about the user's simulation
9+
10+
11+
pub mod postgres_db;
12+
pub mod properties_db;
13+

oscps-db/src/postgres_db.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// #PostgresDB
2+
///
3+
/// Will provide methods to connect to a postgres database to pull relevant property and/or
4+
/// simulation information
5+
///
6+
/// properties:
7+
/// 1. db_name
8+
/// 2. query
9+
/// 3. status
10+
/// 4. connection_key
11+
12+
use sqlx::PgPool;
13+
use uuid::Uuid;
14+
15+
16+
enum DBStatus {
17+
Successful,
18+
Failure,
19+
InProgress
20+
}
21+
22+
pub struct PostgresDB {
23+
pub db_name: String,
24+
pub input_query: String,
25+
pub request_status: DBStatus,
26+
db_key: Uuid,
27+
db_pool: PgPool,
28+
}

oscps-db/src/properties_db.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
///# PropertiesDB
2+
///
3+
///Will formulate the right queries required for 'DBConnector'
4+
///

oscps-gui/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "oscps-gui"
33
version = "0.1.0"
4-
authors = ["Nathaniel Thomas <[email protected]>", "Bhargav Akula <bhargavakula01>"]
4+
authors = ["Nathaniel Thomas <[email protected]>", "Bhargav Akula <[email protected]>"]
55
edition = "2021"
66

77
[dependencies]

oscps-lib/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
[package]
22
name = "oscps-lib"
33
version = "0.1.0"
4+
authors = ["Nathaniel Thomas <[email protected]>", "Bhargav Akula <[email protected]>"]
45
edition = "2021"
56

67
[dependencies]
7-
uom = "0.36.0"
8+
uom = "0.37.0"
89
once_cell = "1.17.1"
910
pubchem = "0.1.1"
10-
reqwest = { version = "0.11", features = ["json"] }
1111
serde = { version = "1.0", features = ["derive"] }
1212
serde_json = "1.0"
1313
tokio = { version = "1", features = ["full"] }
1414
anyhow = "1.0"
15+
autodiff = "0.7.0"
16+
oscps-db = { path = "../oscps-db" }

oscps-lib/src/component.rs

Lines changed: 0 additions & 163 deletions
This file was deleted.

oscps-lib/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
66
#![warn(missing_docs)]
77

8+
extern crate uom;
9+
extern crate once_cell;
10+
extern crate serde;
11+
extern crate anyhow;
12+
813
pub mod blocks;
914
pub mod component;
1015
pub mod simulation;

oscps-lib/src/properties.rs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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

Comments
 (0)