Skip to content

Commit

Permalink
fix(pppdb): update xlsx and fixes relative to condition/properties va…
Browse files Browse the repository at this point in the history
…lues (#32)

* fix(pppdb): update chi.xslx with valid BigSMILES

Single quotes where removed.

* fix(pppdb): ambiguous log

An "other" could be logged as "solvent".

* feat(pppdb): add FetchPubChemResult type

* fix(pppdb): temperature could have undefined value

* fix(pppdb): interaction_param for Type-1

* doc(pppdb): update comments

* doc(pppdb): update comments
  • Loading branch information
bearmit authored Dec 19, 2023
1 parent 2bed3af commit fe7c1f0
Showing 1 changed file with 84 additions and 61 deletions.
145 changes: 84 additions & 61 deletions scripts/typescript/src/pppdb/pppdb-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,34 +299,38 @@ export class PPPDBLoader {

// shared conditions
{
if( !chi_row.chimax ) {

// single temperature value
if( !chi_row.tempmax ) {
this.validate_and_push_condition( shared_by_all_properties, {
node: ['Condition'],
key: 'temperature',
type: 'value',
value: chi_row.temperature,
unit: chi_row.tempunit
});

// min/max temperature values
} else if ( chi_row.temperature ) {
this.validate_and_push_condition( shared_by_all_properties, {
node: ['Condition'],
key: 'temperature',
type: 'min',
value: chi_row.temperature, // temperature is considered as min in such case
unit: chi_row.tempunit
});
this.validate_and_push_condition( shared_by_all_properties, {
node: ['Condition'],
key: 'temperature',
type: 'max',
value: chi_row.tempmax,
unit: chi_row.tempunit
});
if( chi_row.chimax === undefined ) {
if( chi_row.temperature !== undefined) {

// When we have no "tempmax", we store "temperature" as value.
if( chi_row.tempmax === undefined ) {
this.validate_and_push_condition( shared_by_all_properties, {
node: ['Condition'],
key: 'temperature',
type: 'value',
value: chi_row.temperature,
unit: chi_row.tempunit
});

// Otherwise, we store "temperature" as "min", and "tempmax" as "max".
} else {
this.validate_and_push_condition( shared_by_all_properties, {
node: ['Condition'],
key: 'temperature',
type: 'min',
value: chi_row.temperature, // temperature is considered as min in such case
unit: chi_row.tempunit
});
this.validate_and_push_condition( shared_by_all_properties, {
node: ['Condition'],
key: 'temperature',
type: 'max',
value: chi_row.tempmax,
unit: chi_row.tempunit
});
}
} else {
this.logger.warning(`Unable to add condition, "temperature" column is undefined`)
}

if( chi_row.refvolume ) {
Expand Down Expand Up @@ -378,40 +382,47 @@ export class PPPDBLoader {
switch( chi_row.type ) {
case "Type 1":

if( !chi_row.chimax ) {

this.validate_and_push_property(combined_material, {
node: ['Property'],
key: 'interaction_param',
type: 'value',
value: chi_row.chinumber,
uncertainty: chi_row.chierror,
unit: null,
...shared_by_all_properties,
} satisfies IProperty);

} else if (chi_row.chinumber && chi_row.chimax) {

// interaction param (min)
this.validate_and_push_property( combined_material, {
node: ['Property'],
key: 'interaction_param',
type: 'min',
value: chi_row.chinumber,
unit: null,
...shared_by_all_properties,
});

// interaction param (max)
this.validate_and_push_property( combined_material, {
node: ['Property'],
key: 'interaction_param',
type: 'max',
value: chi_row.chimax,
unit: null,
...shared_by_all_properties,
});
if( chi_row.chinumber !== undefined ) {

// If "chimax" is not defined, we interpret "chinumber" as "interaction_param" ("value")
if( chi_row.chimax === undefined ) {
this.validate_and_push_property(combined_material, {
node: ['Property'],
key: 'interaction_param',
type: 'value',
value: chi_row.chinumber,
uncertainty: chi_row.chierror,
unit: null,
...shared_by_all_properties,
} satisfies IProperty);

// Otherwise, we interpret "chinumber" - "interaction_param - "min" and "chimax" as "max".
} else {

// interaction param (min)
this.validate_and_push_property( combined_material, {
node: ['Property'],
key: 'interaction_param',
type: 'min',
value: chi_row.chinumber,
unit: null,
...shared_by_all_properties,
});

// interaction param (max)
this.validate_and_push_property( combined_material, {
node: ['Property'],
key: 'interaction_param',
type: 'max',
value: chi_row.chimax,
unit: null,
...shared_by_all_properties,
});
}
} else if ( chi_row.chimax ) {
this.logger.warning(`chinumber is undefined but chimax is defined, interaction_param skipped`)
}

break;

case 'Type 3':
Expand Down Expand Up @@ -534,6 +545,12 @@ export class PPPDBLoader {
*/
validate_and_push_condition(node_with_condition: { condition: ICondition[]}, condition: ICondition) {
this.validator.validate_or_throw(condition);

// Add a manual check on value (validtion does not detect it)
if( condition.value === undefined ) {
throw new Error(`Condition has an undefined value!`)
}

node_with_condition.condition.push(condition);
}

Expand All @@ -542,6 +559,12 @@ export class PPPDBLoader {
*/
validate_and_push_property(node_with_property: { property: IProperty[] }, property: IProperty): void | never {
this.validator.validate_or_throw(property);

// Add a manual check on value (validation does not detect it)
if( property.value === undefined ) {
throw new Error(`Property has an undefined value!`)
}

node_with_property.property.push(property);
}

Expand Down

0 comments on commit fe7c1f0

Please sign in to comment.