Skip to content

Commit

Permalink
fix #26
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-24 committed Aug 6, 2024
1 parent ebbb0bd commit 78d1022
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"esversion": 8,
"globalstrict": true,
"browser" : true
"browser": true,
"node": true
}
8 changes: 8 additions & 0 deletions cp2k_basis/pseudopotential.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ def read_hdf5(cls, symbol: str, group: h5py.Group) -> 'AtomicPseudopotentialVari

return obj

def preferred_name(self, family_name: str, variant: str) -> str:
"""Even though they can have multiple name, 'ALL' pseudo should be referred to as `ALL`.
"""
if family_name == 'ALL':
return 'ALL'
else:
return super().preferred_name(family_name, variant)


class AtomicPseudopotential(BaseAtomicDataObject):
object_type = AtomicPseudopotentialVariant
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions tests/tests_pseudopotential.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,26 @@ def test_storage_dump_hdf5_ok(self):
'q{}'.format(sum(storage[pp_name][symbol][variant].nelec)),
variant
)

def test_preferred_name_ok(self):
app1 = self.storage['GTH-BLYP']['Ne']['q8']
self.assertEqual(app1.preferred_name('GTH-BLYP', 'q8'), 'GTH-BLYP-q8')

def test_preferred_name_all_ok(self):
name = 'ALL'
storage = PseudopotentialsStorage()

filter_name = FilterUnique([(re.compile(r'^({})$'.format(name)), '\\1')]) # ALL!

with (pathlib.Path(__file__).parent / 'POTENTIAL_ALL_EXAMPLE').open() as f:
storage.update(
AtomicPseudopotentialsParser(f.read()).iter_atomic_pseudopotential_variants(),
filter_name,
self.filter_variant
)

app1 = storage['ALL']['H']['q1']
self.assertEqual(app1.names, ['ALLELECTRON', 'ALL'])

# although "ALLELECTRON" would be choosen, "ALL" is actually selected
self.assertEqual(app1.preferred_name('ALL', 'q1'), 'ALL')

0 comments on commit 78d1022

Please sign in to comment.