Skip to content

Commit

Permalink
add debug asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
mjohnson541 committed Oct 15, 2024
1 parent efea275 commit 0692231
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pynta/coveragedependence.py
Original file line number Diff line number Diff line change
Expand Up @@ -2212,22 +2212,30 @@ def mol_to_atoms(admol,slab,sites,metal,partial_atoms=None,partial_admol=None):
Returns:
_type_: Atoms object corresponding to the admol 2D configuration
"""
assert admol.atoms[1].site == "bridge"
assert partial_admol.atoms[1].site == "bridge"
if partial_atoms and partial_admol:
atoms = deepcopy(partial_atoms)
gpartial_admol = partial_admol.to_group()
admol_atom_order = admol.atoms[:]
gpartial_admol_order = gpartial_admol.atoms[:]
assert admol.atoms[1].site == "bridge"
assert partial_admol.atoms[1].site == "bridge"
try:
subisos = admol.find_subgraph_isomorphisms(gpartial_admol,save_order=True)
except ValueError:
subisos = admol.find_subgraph_isomorphisms(gpartial_admol)
admol.atoms = admol_atom_order
gpartial_admol.atoms = gpartial_admol_order
assert admol.atoms[1].site == "bridge"
assert partial_admol.atoms[1].site == "bridge"
if len(subisos) == 0:
raise ValueError("partial_admol is not subgraph isomorphic to admol: {0}, {1}".format(gpartial_admol.to_adjacency_list(),admol.to_adjacency_list()))
subiso = subisos[0]
atoms_in_partial = [a for a in subiso.keys() if not a.is_surface_site()]
split_structs,adsorbed_atom_dict = split_adsorbed_structures(admol,clear_site_info=False,adsorption_info=True,atoms_to_skip=atoms_in_partial)
assert admol.atoms[1].site == "bridge"
assert partial_admol.atoms[1].site == "bridge"
elif partial_atoms is None and partial_admol is None:
atoms = deepcopy(slab)
split_structs,adsorbed_atom_dict = split_adsorbed_structures(admol,clear_site_info=False,adsorption_info=True)
Expand All @@ -2249,7 +2257,8 @@ def mol_to_atoms(admol,slab,sites,metal,partial_atoms=None,partial_admol=None):
ad.rotate(rot_vec,[0.0,0.0,1.0]) #rotate bonds toward the +z-axis
else:
adatom_molind = st.atoms.index([a for a in st.atoms if not a.is_surface_site()][0])

assert admol.atoms[1].site == "bridge"
assert partial_admol.atoms[1].site == "bridge"
atom_surf_inds = []
ad_sites = []
for a,sind in adsorbed_atom_dict.items():
Expand All @@ -2258,4 +2267,6 @@ def mol_to_atoms(admol,slab,sites,metal,partial_atoms=None,partial_admol=None):
atom_surf_inds.append(mol_to_atoms_map[adatom_molind])
ad_sites.append(sites[sind])
atoms,_,_ = place_adsorbate(ad,atoms,atom_surf_inds,ad_sites,metal)
assert admol.atoms[1].site == "bridge"
assert partial_admol.atoms[1].site == "bridge"
return atoms
4 changes: 4 additions & 0 deletions pynta/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1242,14 +1242,18 @@ def run_task(self, fw_spec):
sample_fws = []
calculation_directories = []
for i,config in enumerate(configs_for_calculation):
assert config.atoms[1].site == "bridge"
adname = None
for admol_name,config_list in admol_to_config_for_calculation.items():
if config in config_list:
adname = admol_name
break
else:
raise ValueError
assert config.atoms[1].site == "bridge"

partial_admol = admol_name_structure_dict[adname]
assert partial_admol.atoms[1].site == "bridge"
admol_path = admol_name_path_dict[adname]
partial_atoms = read(admol_path)
init_atoms = mol_to_atoms(config,slab,sites,metal,partial_atoms=partial_atoms,partial_admol=partial_admol)
Expand Down

0 comments on commit 0692231

Please sign in to comment.