-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from openkim/disclaimer
Disclaimer
- Loading branch information
Showing
6 changed files
with
203 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,14 @@ Creating property instances:: | |
"instance-id" 2 | ||
} | ||
] | ||
|
||
>>> kim_property_create(1, 'cohesive-energy-relation-cubic-crystal', property_disclaimer="This is an example disclaimer.") | ||
'[{"property-id" "tag:[email protected],2014-04-15:property/cohesive-energy-relation-cubic-crystal" "instance-id" 1 "disclaimer" "This is an example disclaimer."}]' | ||
|
||
>>> property_inst = kim_property_create(1, 'cohesive-energy-relation-cubic-crystal') | ||
|
||
>>> kim_property_create(2, 'atomic-mass', property_inst, "This is an example disclaimer for atomic-mass.") | ||
'[{"property-id" "tag:[email protected],2014-04-15:property/cohesive-energy-relation-cubic-crystal" "instance-id" 1} {"property-id" "tag:[email protected],2016-05-11:property/atomic-mass" "instance-id" 2 "disclaimer" "This is an example disclaimer for atomic-mass."}]' | ||
```` | ||
|
||
A property instance is stored in a subset of the KIM-EDN format as described in | ||
|
@@ -170,6 +178,26 @@ An instance of this property could be created like so:: | |
} | ||
} | ||
] | ||
|
||
>>> property_inst = kim_property_create(1, 'cohesive-energy-relation-cubic-crystal') | ||
>>> property_inst = kim_property_modify(property_inst, 1, | ||
"disclaimer", "This is an example disclaimer.", | ||
"key", "short-name", | ||
"source-value", "1", "fcc") | ||
>>> property_inst_obj = kim_edn.loads(property_inst) | ||
>>> print(kim_edn.dumps(property_inst_obj, indent=4)) | ||
[ | ||
{ | ||
"property-id" "tag:[email protected],2014-04-15:property/cohesive-energy-relation-cubic-crystal" | ||
"instance-id" 1 | ||
"disclaimer" "This is an example disclaimer." | ||
"short-name" { | ||
"source-value" [ | ||
"fcc" | ||
] | ||
} | ||
} | ||
] | ||
```` | ||
|
||
For cases where there are multiple keys or a key receives an array of values | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,44 @@ def test_create(self): | |
self.assertRaises(self.KIMPropertyError, self.kim_property.kim_property_create, | ||
'3', 'cohesive-energy-relation-cubic-crystal') | ||
|
||
def test_create_with_optional_keys(self): | ||
"""Test the create functionality with optional keys.""" | ||
# Correct object | ||
str_obj = '[{"property-id" "tag:[email protected],2014-04-15:property/' \ | ||
'cohesive-energy-relation-cubic-crystal" "instance-id" 1 ' \ | ||
'"disclaimer" "This is an example disclaimer."}]' | ||
|
||
# Create the property instance with the property name | ||
str1 = self.kim_property.kim_property_create( | ||
1, 'cohesive-energy-relation-cubic-crystal', | ||
property_disclaimer='This is an example disclaimer.') | ||
|
||
self.assertTrue(str1 == str_obj) | ||
|
||
str_obj2 = '[{"property-id" "tag:[email protected],2014-04-15:property/' \ | ||
'cohesive-energy-relation-cubic-crystal" "instance-id" 1 ' \ | ||
'"disclaimer" "This is an example disclaimer."} {"property-id" ' \ | ||
'"tag:[email protected],2016-05-11:property/atomic-mass" ' \ | ||
'"instance-id" 2 "disclaimer" "This is another example disclaimer."}]' | ||
|
||
# Create the property instance with the property name to the already created instance | ||
str3 = self.kim_property.kim_property_create( | ||
2, 'atomic-mass', str1, 'This is another example disclaimer.') | ||
|
||
self.assertTrue(str3 == str_obj2) | ||
|
||
str4 = self.kim_property.kim_property_create( | ||
2, 'atomic-mass', property_instances=str1, | ||
property_disclaimer='This is another example disclaimer.') | ||
|
||
self.assertTrue(str4 == str_obj2) | ||
|
||
import kim_edn | ||
self.assertRaises(kim_edn.decoder.KIMEDNDecodeError, | ||
self.kim_property.kim_property_create, | ||
2, 'atomic-mass', | ||
'This is another example disclaimer.') | ||
|
||
def test_create_from_a_file(self): | ||
"""Test the create functionality for a new file as input.""" | ||
# Correct object | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,77 @@ def test_modify(self): | |
"key", "cohesive-potential-energy", | ||
"si-unit", "eV-test") | ||
|
||
def test_modify_with_optional_keys(self): | ||
"""Test the modify functionality with optional keys.""" | ||
# Create the property instance with the property name | ||
str_obj = self.kim_property.kim_property_create( | ||
1, 'cohesive-energy-relation-cubic-crystal') | ||
|
||
str_obj = self.kim_property.kim_property_modify( | ||
str_obj, 1, "disclaimer", "This is an example disclaimer.") | ||
|
||
kim_obj = kim_edn.load(str_obj)[0] | ||
|
||
Property_Instance = '{"property-id" "tag:[email protected],2014-04-15:property/' \ | ||
'cohesive-energy-relation-cubic-crystal" "instance-id" 1 ' \ | ||
'"disclaimer" "This is an example disclaimer."}' | ||
|
||
self.assertTrue(Property_Instance == kim_edn.dumps(kim_obj)) | ||
|
||
self.assertRaises(self.KIMPropertyError, | ||
self.kim_property.kim_property_modify, | ||
str_obj, 1, | ||
"disclaimer") | ||
|
||
str_obj = self.kim_property.kim_property_modify( | ||
str_obj, 1, | ||
"key", "short-name", | ||
"source-value", "1", "fcc", | ||
"disclaimer", "This is a new example disclaimer.") | ||
|
||
kim_obj = kim_edn.load(str_obj)[0] | ||
|
||
Property_Instance = '{"property-id" "tag:[email protected],2014-04-15:property/' \ | ||
'cohesive-energy-relation-cubic-crystal" "instance-id" 1 ' \ | ||
'"disclaimer" "This is a new example disclaimer." ' \ | ||
'"short-name" {"source-value" ["fcc"]}}' | ||
|
||
self.assertTrue(Property_Instance == kim_edn.dumps(kim_obj)) | ||
|
||
# Create the property instance with the property name | ||
str_obj = self.kim_property.kim_property_create( | ||
1, 'cohesive-energy-relation-cubic-crystal') | ||
|
||
# Create the property instance with the property name | ||
str_obj = self.kim_property.kim_property_create( | ||
2, 'atomic-mass', property_instances=str_obj, | ||
property_disclaimer="This is an example disclaimer for atomic-mass.") | ||
|
||
str_obj = self.kim_property.kim_property_modify( | ||
str_obj, 1, | ||
"disclaimer", "This is an example disclaimer for cohesive-energy.") | ||
|
||
kim_obj = kim_edn.load(str_obj) | ||
|
||
self.assertTrue( | ||
kim_obj[0]["disclaimer"] == "This is an example disclaimer for cohesive-energy.") | ||
|
||
self.assertTrue( | ||
kim_obj[1]["disclaimer"] == "This is an example disclaimer for atomic-mass.") | ||
|
||
# Create the property instance with the property name | ||
str_obj = self.kim_property.kim_property_create( | ||
1, 'cohesive-energy-relation-cubic-crystal') | ||
|
||
self.assertRaises(self.KIMPropertyError, | ||
self.kim_property.kim_property_modify, | ||
str_obj, 1, | ||
"key", "short-name", | ||
"source-value", "1", "fcc", | ||
"key", "species", | ||
"disclaimer", "This is an example disclaimer.", | ||
"source-value", "1:4", "Al", "Al", "Al", "Al") | ||
|
||
def test_modify_exception(self): | ||
"""Test the modify functionality on exceptions.""" | ||
# Fails when the input is none or not created | ||
|