Skip to content

Fix atom type consistency#10

Merged
chaibhave merged 3 commits intoIdahoLabResearch:mainfrom
jarinfrench:fix_atom_type_consistency
Apr 13, 2026
Merged

Fix atom type consistency#10
chaibhave merged 3 commits intoIdahoLabResearch:mainfrom
jarinfrench:fix_atom_type_consistency

Conversation

@jarinfrench
Copy link
Copy Markdown
Collaborator

No description provided.

@jarinfrench jarinfrench marked this pull request as draft January 21, 2026 20:11
@jarinfrench jarinfrench force-pushed the fix_atom_type_consistency branch from 2a44ce0 to 8806920 Compare January 21, 2026 20:35
@jarinfrench jarinfrench marked this pull request as ready for review January 21, 2026 20:36
jarinfrench and others added 3 commits April 8, 2026 16:14
…LabResearch#9

- Atom.py: use dict.fromkeys instead of set() to preserve insertion order
  when auto-generating type_map, preventing non-deterministic type IDs.
- GBMaker.py: reuse unit_cell.type_map IDs when writing LAMMPS files if
  atom names are a known subset, preventing ID drift across writes.
- GBManipulator.py: accept type_dict as dict[str,int] or dict[int,str]
  and normalise to both directions internally; auto-derive from
  unit_cell.type_map when not explicitly supplied; pass type_map to
  Atom.as_array in remove_atoms/insert_atoms; fix bytes handling in
  convert_type; fix atoms_to_add keyed by atom_type not ratio; replace
  identity comparison with equality for central_type check.
- tests: add roundtrip test verifying element names survive
  write→read cycles after translate, remove, insert, slice_and_merge,
  and soft-mode displacement.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace bare dict/list access with None-safe handling throughout
  _evaluate_generation: wrap gb_energy_func calls in try/except and
  assign a PENALTY (1e30) to any candidate that errors or produces a
  missing dump file.
- Add _is_valid_file helper to safely test dump file existence.
- Guard _make_next_generation against empty files or indices lists.
- Filter valid candidates before selection: build valid_old_idxs,
  valid_energies, and valid_files so selection only operates on
  survivors; re-seed entirely from the current best when no candidates
  survive a generation.
- Copy initial system arrays (np.array(..., copy=True)) before passing
  to the energy function to prevent in-place mutation side-effects.
- Add **kwargs pass-through to run_MC and preserve type_dict when
  reconstructing the manipulator after an accepted MC step.
- Switch imports: pathlib.Path replaces sys; typing.Optional added.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Both MonteCarloMinimizer and GeneticAlgorithmMinimizer accept an
  optional initial_structure keyword argument (None, GBMaker, or a file
  path) that seeds the starting manipulator instead of always
  constructing one fresh from self.GB.
- _make_initial_manipulator() encapsulates this logic on both classes.
- Mutator.mutate() now returns (mutation_label, new_system) so callers
  can record what operation was applied.
- MonteCarloMinimizer tracks the full accept/reject history in
  operation_list as [mutation_label, accepted] pairs; the initial entry
  is ["START", True]. Closes IdahoLabResearch#7
- GeneticAlgorithmMinimizer seeds one member of the initial population
  directly from the evaluated initial structure when initial_structure
  is supplied.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jarinfrench jarinfrench force-pushed the fix_atom_type_consistency branch from 8806920 to 11ec56b Compare April 9, 2026 19:32
@jarinfrench
Copy link
Copy Markdown
Collaborator Author

This PR supersedes #8, and closes #7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants