Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions dpgen2/exploration/task/caly_task_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,19 @@ def set_params(
self.atomic_number = [atomic_symbols.index(i) for i in self.name_of_atoms]
else:
self.name_of_atoms = name_of_atoms
self.atomic_number = atomic_number

if isinstance(distance_of_ions, dict):
self.atomic_number = (
[atomic_number_map[name] for name in self.name_of_atoms]
if atomic_number is None
else atomic_number
)

if distance_of_ions is None or isinstance(distance_of_ions, dict):
# Generate a complete distance matrix from the maintained
# covalent-radius table when the optional matrix is omitted.
updated_table = copy.deepcopy(covalent_radii)
for key, value in distance_of_ions.items():
updated_table[atomic_number_map[key]] = value
if isinstance(distance_of_ions, dict):
for key, value in distance_of_ions.items():
updated_table[atomic_number_map[key]] = value

temp_distance_mtx = np.zeros((numb_of_species, numb_of_species))
for i in range(numb_of_species):
Expand Down
15 changes: 15 additions & 0 deletions tests/exploration/test_make_task_group_from_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,18 @@ def test_make_caly_input(self):
def test_caly_task_group(self):
tgroup = make_calypso_task_group_from_config(self.config)
self.assertTrue(isinstance(tgroup, CalyTaskGroup))

def test_infers_optional_atomic_numbers_and_distances(self):
"""Generate CALYPSO-required values when optional fields are absent."""
config = {
"name_of_atoms": ["Li", "La"],
"numb_of_atoms": [10, 10],
"numb_of_species": 2,
}

task_group = make_calypso_task_group_from_config(config)

self.assertEqual(task_group.atomic_number, [3, 57])
self.assertEqual(task_group.distance_of_ions.shape, (2, 2))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two assertions only establish that a square, positive matrix was produced. I mutated the source four ways (0.7 -> 7.0; radius index +1; dict-override loop replaced by if False; matrix replaced by a constant 0.01) and all five tests stayed green each time.

Please pin the values instead. For this Li/La config:

np.testing.assert_allclose(
    task_group.distance_of_ions, [[1.79, 2.34], [2.34, 2.90]]
)

and one dict case, since no test in the repo pins an override value and this PR restructures that loop: distance_of_ions={"Li": 2.0} on the same config gives [[2.8, 2.85], [2.85, 2.9]].

The atomic_number == [3, 57] line above is fine; it does catch an off-by-one in the symbol table.

self.assertTrue(np.all(task_group.distance_of_ions > 0))
self.assertEqual(len(task_group.make_task()), 1)