FAQ
| This is a
LIVE
service |
Changelog
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
solventmapcreator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yusuf Hamied Department of Chemistry
Hunter Group
SSIPtools
SSIMPLEapps
solventmapcreator
Commits
fcea2c82
Commit
fcea2c82
authored
6 years ago
by
M.D. Driver
Browse files
Options
Downloads
Patches
Plain Diff
added methods for writing to file after extracting the required values, and updated tests.
parent
55c00baf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
solventmapcreator/io/solvationenergyextraction.py
+27
-0
27 additions, 0 deletions
solventmapcreator/io/solvationenergyextraction.py
solventmapcreator/test/iotest/solvationenergyextractiontest.py
+47
-8
47 additions, 8 deletions
...ntmapcreator/test/iotest/solvationenergyextractiontest.py
with
74 additions
and
8 deletions
solventmapcreator/io/solvationenergyextraction.py
+
27
−
0
View file @
fcea2c82
...
...
@@ -35,6 +35,33 @@ def get_solvent_id_list(solvent_list_element_tree):
LOGGER
.
info
(
"
Solvent IDs found %i
"
,
len
(
solvent_ids
))
return
solvent_ids
def
extract_and_write_energy_values_for_solvent_list
(
solvent_id_list
,
energy_xml
,
energy_type
,
directory
):
"""
This extracts the energies for each solvent and writes the energies found to a new file per solvent.
"""
for
solvent_id
in
solvent_id_list
:
extract_and_write_energy_values_for_solvent
(
solvent_id
,
energy_xml
,
energy_type
,
directory
)
def
extract_and_write_energy_values_for_solvent
(
solvent_id
,
energy_xml
,
energy_type
,
directory
):
"""
This extracts the elements and writes the energies found ot a new file.
"""
energy_values_element
=
generate_energy_values_element_for_solvent
(
solvent_id
,
energy_xml
,
energy_type
)
element_tree
=
create_element_tree
(
energy_values_element
)
outfilename
=
directory
+
create_output_filename
(
solvent_id
,
energy_type
)
write_element_tree_to_file
(
element_tree
,
outfilename
)
def
generate_energy_values_element_for_solvent
(
solvent_id
,
energy_xml
,
energy_type
):
"""
This extracts the elements for the solvents and creates a new EnergyValues element.
"""
if
energy_type
==
"
binding
"
:
xpath_expression
=
generate_binding_energy_xpath_expression
(
solvent_id
)
energy_elements
=
get_energy_elements
(
energy_xml
,
xpath_expression
)
return
generate_energy_values_element
(
energy_elements
,
energy_type
)
elif
energy_type
==
"
free
"
:
xpath_expression
=
generate_free_energy_xpath_expression
(
solvent_id
)
energy_elements
=
get_energy_elements
(
energy_xml
,
xpath_expression
)
return
generate_energy_values_element
(
energy_elements
,
energy_type
)
def
create_output_filename
(
to_solvent_id
,
energy_type
):
"""
This creates an output filename based on the solvent id and energy type.
"""
...
...
This diff is collapsed.
Click to expand it.
solventmapcreator/test/iotest/solvationenergyextractiontest.py
+
47
−
8
View file @
fcea2c82
...
...
@@ -22,13 +22,14 @@ class SolvationEnergyExtractionTestCase(unittest.TestCase):
def
setUp
(
self
):
"""
Set up for tests
"""
self
.
maxDiff
=
None
self
.
solvent_filename
=
"
resources/watersolvent.xml
"
self
.
solvent_xml
=
solvationenergyextraction
.
read_xml_file
(
self
.
solvent_filename
)
self
.
binding_energy_filename
=
"
resources/energyvaluestest.xml
"
self
.
free_energy_filename
=
"
resources/energyvaluestest2.xml
"
self
.
actual_output_filename
=
"
resources/watersolvation.xml
"
self
.
actual_output_filename2
=
"
water.xml
"
self
.
actual_output_filename3
=
"
water.xml
"
self
.
actual_output_filename2
=
"
water
free
.xml
"
self
.
actual_output_filename3
=
"
water
binding
.xml
"
self
.
binding_energy_xml
=
solvationenergyextraction
.
read_xml_file
(
self
.
binding_energy_filename
)
self
.
free_energy_xml
=
solvationenergyextraction
.
read_xml_file
(
self
.
free_energy_filename
)
def
tearDown
(
self
):
...
...
@@ -46,11 +47,6 @@ class SolvationEnergyExtractionTestCase(unittest.TestCase):
if
os
.
path
.
isfile
(
self
.
actual_output_filename3
):
os
.
remove
(
self
.
actual_output_filename3
)
del
self
.
actual_output_filename3
def
test_
(
self
):
"""
"""
self
.
fail
(
"
not implemented
"
)
def
test_read_in_solvent_id_list
(
self
):
"""
Test to see if expected solvent ID list is returned.
"""
...
...
@@ -63,6 +59,39 @@ class SolvationEnergyExtractionTestCase(unittest.TestCase):
expected_solvent_list
=
[
"
water
"
]
actual_list
=
solvationenergyextraction
.
get_solvent_id_list
(
self
.
solvent_xml
)
self
.
assertListEqual
(
expected_solvent_list
,
actual_list
)
def
test_extract_and_write_energy_values_for_solvent_list
(
self
):
"""
Test to see if expected files is produced.
"""
solvationenergyextraction
.
extract_and_write_energy_values_for_solvent_list
([
"
water
"
],
self
.
binding_energy_xml
,
"
binding
"
,
""
)
with
open
(
self
.
actual_output_filename3
,
"
r
"
)
as
actual_file
:
actual_xml
=
actual_file
.
read
()
with
open
(
"
resources/energyvaluestest.xml
"
)
as
expected_file
:
expected_xml
=
expected_file
.
read
()
self
.
assertEqual
(
expected_xml
,
actual_xml
)
def
test_extract_and_write_energy_values_for_solvent
(
self
):
"""
Test to see if expected file is produced.
"""
solvationenergyextraction
.
extract_and_write_energy_values_for_solvent
(
"
water
"
,
self
.
free_energy_xml
,
"
free
"
,
""
)
with
open
(
self
.
actual_output_filename2
,
"
r
"
)
as
actual_file
:
actual_xml
=
actual_file
.
read
()
with
open
(
"
resources/energyvaluestest2.xml
"
)
as
expected_file
:
expected_xml
=
expected_file
.
read
()
self
.
assertEqual
(
expected_xml
,
actual_xml
)
def
test_generate_energy_values_element_for_solvent
(
self
):
"""
Test to see expected energy values is produced.
"""
expected_xml
=
"""
<phase:EnergyValues xmlns:phase=
"
http://www-hunter.ch.cam.ac.uk/PhaseSchema
"
>
<phase:FreeEnergyCollection><phase:FreeEnergy phase:moleculeID=
"
-14.100solute
"
phase:fromSolventID=
""
phase:toSolventID=
"
water
"
phase:valueType=
"
MOLEFRACTION
"
>
<phase:TotalEnergy>-34.8195308084233</phase:TotalEnergy>
<phase:EnergyContributions>
<phase:EnergyContribution phase:ssipID=
"
1
"
>-34.8195308084233</phase:EnergyContribution>
</phase:EnergyContributions>
</phase:FreeEnergy>
</phase:FreeEnergyCollection>
</phase:EnergyValues>
"""
actual_element
=
solvationenergyextraction
.
generate_energy_values_element_for_solvent
(
"
water
"
,
self
.
free_energy_xml
,
"
free
"
)
self
.
assertMultiLineEqual
(
expected_xml
,
etree
.
tounicode
(
actual_element
,
pretty_print
=
True
))
def
test_create_output_filename
(
self
):
"""
Test to see if expected filename is produced.
"""
...
...
@@ -72,7 +101,17 @@ class SolvationEnergyExtractionTestCase(unittest.TestCase):
def
test_write_element_tree_to_file
(
self
):
"""
Test to see if expecetd file is written.
"""
self
.
fail
(
"
not implemented
"
)
xpath_expression
=
solvationenergyextraction
.
generate_free_energy_xpath_expression
(
"
water
"
)
free_elements
=
solvationenergyextraction
.
get_energy_elements
(
self
.
free_energy_xml
,
xpath_expression
)
energy_values_element
=
solvationenergyextraction
.
generate_energy_values_element
(
free_elements
,
"
free
"
)
energy_values_tree
=
solvationenergyextraction
.
create_element_tree
(
energy_values_element
)
solvationenergyextraction
.
write_element_tree_to_file
(
energy_values_tree
,
self
.
actual_output_filename
)
with
open
(
self
.
actual_output_filename
,
"
r
"
)
as
actual_file
:
actual_xml
=
actual_file
.
read
()
with
open
(
"
resources/energyvaluestest2.xml
"
)
as
expected_file
:
expected_xml
=
expected_file
.
read
()
self
.
assertEqual
(
expected_xml
,
actual_xml
)
def
test_create_element_tree
(
self
):
"""
Test to see if expected element tree is produced.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment