/
test_interactive.py
139 lines (123 loc) · 4.75 KB
/
test_interactive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.
import os
import numpy as np
import unittest
import warnings
from pyiron.project import Project
from pyiron.atomistics.structure.periodic_table import PeriodicTable
from pyiron.atomistics.structure.atoms import Atoms
class InteractiveLibrary(object):
def __init__(self):
self.command = []
def write(self, line):
self.command.append(line)
def flush(self):
return None
class TestSphinx(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.file_location = os.path.dirname(os.path.abspath(__file__))
cls.project = Project(os.path.join(cls.file_location, "../static/sphinx"))
cls.sphinx = cls.project.create_job("Sphinx", "job_sphinx")
cls.sphinx.structure = Atoms(elements=['Fe']*2, scaled_positions=[3*[0.0], 3*[0.5]], cell=2.6*np.eye(3))
cls.sphinx.structure.set_initial_magnetic_moments(np.ones(2))
cls.current_dir = os.path.abspath(os.getcwd())
cls.sphinx._create_working_directory()
cls.sphinx.input["VaspPot"] = False
cls.sphinx.write_input()
cls.sphinx.version = "2.6"
cls.sphinx.server.run_mode.interactive = True
def setUp(self):
self.sphinx._interactive_library = InteractiveLibrary()
@classmethod
def tearDownClass(cls):
cls.file_location = os.path.dirname(os.path.abspath(__file__))
os.remove(
os.path.join(
cls.file_location,
"../static/sphinx/job_sphinx_hdf5/job_sphinx/basis.sx",
)
)
os.remove(
os.path.join(
cls.file_location,
"../static/sphinx/job_sphinx_hdf5/job_sphinx/control.sx",
)
)
os.remove(
os.path.join(
cls.file_location,
"../static/sphinx/job_sphinx_hdf5/job_sphinx/guess.sx",
)
)
os.remove(
os.path.join(
cls.file_location,
"../static/sphinx/job_sphinx_hdf5/job_sphinx/hamilton.sx",
)
)
os.remove(
os.path.join(
cls.file_location,
"../static/sphinx/job_sphinx_hdf5/job_sphinx/input.sx",
)
)
os.remove(
os.path.join(
cls.file_location,
"../static/sphinx/job_sphinx_hdf5/job_sphinx/potentials.sx",
)
)
os.remove(
os.path.join(
cls.file_location,
"../static/sphinx/job_sphinx_hdf5/job_sphinx/structure.sx",
)
)
os.remove(
os.path.join(
cls.file_location,
"../static/sphinx/job_sphinx_hdf5/job_sphinx/userparameters.sx",
)
)
os.remove(
os.path.join(
cls.file_location,
"../static/sphinx/job_sphinx_hdf5/job_sphinx/Fe_GGA.atomicdata",
)
)
os.rmdir(
os.path.join(
cls.file_location, "../static/sphinx/job_sphinx_hdf5/job_sphinx"
)
)
os.rmdir(os.path.join(cls.file_location, "../static/sphinx/job_sphinx_hdf5"))
def test_interactive_cells_setter(self):
with self.assertRaises(NotImplementedError):
self.sphinx.interactive_cells_setter(np.eye(3))
def test_coarse_run(self):
self.assertFalse(self.sphinx.coarse_run)
with self.assertRaises(ValueError) as c:
self.sphinx.coarse_run = 1
self.assertTrue('boolean' in c.exception)
self.sphinx.coarse_run = True
self.assertTrue(self.sphinx.coarse_run)
def test_interactive_pipe_write(self):
with self.assertRaises(TypeError) as c:
self.sphinx._interactive_pipe_write(self.sphinx)
def test_interactive_positions_setter(self):
self.sphinx.interactive_positions_setter(np.zeros((2,3)))
self.assertEqual(self.sphinx._interactive_library.command,
['set structure\n', '0.0\n', '0.0\n', '0.0\n', '0.0\n', '0.0\n', '0.0\n'])
def test_interactive_spin_constraints_setter(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
self.sphinx.interactive_spin_constraints_setter(np.zeros(2))
self.assertEqual(len(w), 1)
self.sphinx.fix_spin_constraint = True
self.sphinx.interactive_spin_constraints_setter(np.zeros(2))
self.assertEqual(self.sphinx._interactive_library.command, ['set spinconstraint\n', '0.0\n', '0.0\n'])
if __name__ == "__main__":
unittest.main()