Let's assume we want to upload a newly created isotherm in the internal database. This isotherm is measured on the novel adsorbent Carbon X1, with nitrogen at 77 K. The sample itself is synthesised locally, by Dr. Alice and has then undergone a chemical activation process. The experiment is performed on a homemade apparatus by Dr. Bob.
In [1]:
import pygaps
The internal database already contains nitrogen as an adsorbate therefore, there's no need to worry about the adsorbate for now.
In [2]:
novel_material = pygaps.Material(
name = 'Carbon',
batch = 'X1',
contact = 'Alice',
source = 'local',
treatment = 'etched'
)
try:
pygaps.db_upload_material(pygaps.DATABASE, novel_material)
except Exception as e:
print(e)
We get a foreign key error, since the constraints do not exist in the database yet. Before we can upload the sample, we need to have the values of the foreign keys in place:
We can do this by passing to the respective functions dictionaries with the required values.
In [3]:
pygaps.db_upload_material_property_type(pygaps.DATABASE, { 'type' : 'contact'})
pygaps.db_upload_material_property_type(pygaps.DATABASE, { 'type' : 'source'})
pygaps.db_upload_material_property_type(pygaps.DATABASE, { 'type' : 'treatment'})
Now that all of the constraints are in place let's try the sample upload again.
In [4]:
pygaps.db_upload_material(pygaps.DATABASE, novel_material)
In [5]:
import os
json_path = os.path.join(os.getcwd(), 'data', 'database', 'Carbon X1.json')
with open(json_path) as text_file:
isotherm = pygaps.isotherm_from_json(text_file.read())
try:
pygaps.db_upload_isotherm(pygaps.DATABASE, isotherm)
except Exception as e:
print(e)
As before, we need to first make sure that the constraints are satisfied before the isotherm can be uploaded. On the isotherm side, we have the following constraints:
Again, we pass to the respective functions dictionaries with the required values.
In [6]:
pygaps.db_upload_isotherm_type(pygaps.DATABASE, {
'type' : 'physisorption',
'description' : 'physisorption at 77 k'
})
pygaps.db_upload_isotherm_data_type(pygaps.DATABASE, {'type' : isotherm.loading_key})
pygaps.db_upload_isotherm_data_type(pygaps.DATABASE, {'type' : isotherm.pressure_key})
pygaps.db_upload_isotherm_property_type(pygaps.DATABASE, {'type':'t_act'})
pygaps.db_upload_isotherm_property_type(pygaps.DATABASE, {'type':'machine'})
pygaps.db_upload_isotherm_property_type(pygaps.DATABASE, {'type':'user'})
pygaps.db_upload_isotherm_property_type(pygaps.DATABASE, {'type':'lab'})
Now we can try the upload again.
In [7]:
pygaps.db_upload_isotherm(pygaps.DATABASE, isotherm)
In [8]:
pygaps.db_delete_isotherm(pygaps.DATABASE, isotherm)
pygaps.db_delete_material(pygaps.DATABASE, novel_material)
pygaps.db_delete_material_property_type(pygaps.DATABASE, 'treatment')
pygaps.db_delete_material_property_type(pygaps.DATABASE, 'source')
pygaps.db_delete_material_property_type(pygaps.DATABASE, 'contact')
pygaps.db_delete_isotherm_type(pygaps.DATABASE, 'physisorption')
pygaps.db_delete_isotherm_property_type(pygaps.DATABASE, 't_act')
pygaps.db_delete_isotherm_property_type(pygaps.DATABASE, 'machine')
pygaps.db_delete_isotherm_property_type(pygaps.DATABASE, 'user')
pygaps.db_delete_isotherm_property_type(pygaps.DATABASE, 'lab')
pygaps.db_delete_isotherm_data_type(pygaps.DATABASE, isotherm.loading_key)
pygaps.db_delete_isotherm_data_type(pygaps.DATABASE, isotherm.pressure_key)