@@ -6,6 +6,8 @@ extern crate uom;
66
77extern crate pubchem;
88use anyhow:: Result ;
9+ use std:: { thread, time:: Duration } ;
10+
911
1012#[ allow( dead_code) ]
1113/// This will hold the list of chemicals used within the simulation
@@ -43,9 +45,23 @@ impl Chemical {
4345 ChemicalIdentifier :: PubchemID ( id) => pubchem:: Compound :: new ( id) ,
4446 ChemicalIdentifier :: CompoundName ( name) => pubchem:: Compound :: with_name ( name. as_str ( ) ) ,
4547 } ;
46-
47- let cid_vec = pubchem_chemical_object. cids ( ) . unwrap ( ) ;
48- let cid: i32 = cid_vec[ 0 ] ;
48+ let mut request_counter = 0 ;
49+ let mut cid_vec = None ;
50+ while request_counter <= 10 {
51+ match pubchem_chemical_object. cids ( ) {
52+ Ok ( cid_list) => {
53+ cid_vec = Some ( cid_list) ;
54+ break ;
55+ } ,
56+ _ => {
57+ request_counter = request_counter + 1 ;
58+ thread:: sleep ( Duration :: from_secs ( 10 ) ) ;
59+ }
60+ } ;
61+ }
62+
63+ // let cid_vec = pubchem_chemical_object.cids().unwrap();
64+ let cid: i32 = cid_vec. unwrap ( ) [ 0 ] ;
4965 let prop = ChemicalProperties :: new ( cid) . unwrap ( ) ;
5066 return Ok ( Chemical {
5167 pubchem_obj : pubchem_chemical_object,
@@ -93,14 +109,16 @@ impl ChemicalProperties {
93109#[ cfg( test) ]
94110mod chemical_species_tests {
95111 use crate :: component:: { Chemical , ChemicalIdentifier } ;
112+ use std:: { thread, time:: Duration } ;
96113
97114 #[ test]
98115 fn test_create_chemical_from_pubchem_id ( ) {
99116 // Using a known PubChem ID, e.g., 7732 (water)
100117 let identifier = ChemicalIdentifier :: PubchemID ( 7732 ) ;
101118
102119 let chemical = Chemical :: new ( identifier) ;
103-
120+ thread:: sleep ( Duration :: from_secs ( 10 ) ) ;
121+
104122 assert ! (
105123 chemical. is_ok( ) ,
106124 "Failed to create chemical from PubChem ID"
@@ -119,6 +137,8 @@ mod chemical_species_tests {
119137 let identifier = ChemicalIdentifier :: CompoundName ( String :: from ( "Water" ) ) ;
120138
121139 let chemical = Chemical :: new ( identifier) ;
140+ thread:: sleep ( Duration :: from_secs ( 10 ) ) ;
141+
122142
123143 assert ! ( chemical. is_ok( ) , "Failed to create chemical from name" ) ;
124144 let chemical = chemical. unwrap ( ) ;
0 commit comments