Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/SOF-7427 feat: ASE distance norm calculator #160

Merged
merged 23 commits into from
Sep 19, 2024
Merged

Conversation

VsevolodX
Copy link
Member

@VsevolodX VsevolodX commented Sep 2, 2024

  • feat: add ASE calculator
  • add docstrings explaining
  • add required forces defintions and calculations

@VsevolodX VsevolodX changed the base branch from main to feature/SOF-7426 September 2, 2024 21:22
@@ -167,3 +167,100 @@ def calculate_norm_of_distances(material: Material, shadowing_radius: float = 2.
substrate_coordinates_values = np.array(substrate_atoms_surface_coordinates.values)

return get_norm_of_distances_between_coordinates(film_coordinates_values, substrate_coordinates_values)


class SurfaceDistanceCalculator(ASECalculator):
Copy link
Member

Choose a reason for hiding this comment

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

FixedZ

Copy link
Member Author

Choose a reason for hiding this comment

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

Uhm, we pass this as a paramter: whether to fix_z, fix_substrate or not

Copy link
Member

@timurbazhirov timurbazhirov Sep 14, 2024

Choose a reason for hiding this comment

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

FilmSubstrateDistanceCalculator


ASECalculator.calculate(self, atoms, properties, system_changes)
material = Material(from_ase(atoms))
norm = calculate_norm_of_distances(material, self.shadowing_radius)
Copy link
Member

Choose a reason for hiding this comment

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

energies

atoms.set_constraint(constraints)
return atoms

def _calculate_forces(self, atoms: ASEAtoms, norm: float) -> np.ndarray:
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can remove this

Args:
shadowing_radius (float): The radius for atom to shadow underlying from being considered surface, in Angstroms.
force_constant (float): The force constant for the finite difference approximation of the forces.
fix_substrate (bool): Whether to fix the substrate atoms.
Copy link
Member

Choose a reason for hiding this comment

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

is_substrate_fixed, is_z_axis_fixed

force_constant (float): The force constant for the finite difference approximation of the forces.
fix_substrate (bool): Whether to fix the substrate atoms.
fix_z (bool): Whether to fix atoms movement in the z direction.
symprec (float): The symmetry precision for the ASE calculator.
Copy link
Member

Choose a reason for hiding this comment

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

What is that - let's put a link to the original explanation


ASECalculator.calculate(self, atoms, properties, system_changes)
material = Material(from_ase(atoms))
energy = calculate_film_substrate_interaction_metric(material, self.shadowing_radius)
Copy link
Member

@timurbazhirov timurbazhirov Sep 14, 2024

Choose a reason for hiding this comment

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

This should be MaterialCalculator.get_energy(material, calculator_parameters**)

shadowing_radius (float): Radius for atoms shadowing underlying from being treated as a surface, in Angstroms.
force_constant (float): The force constant for the finite difference approximation of the
Note:
Built following: https://wiki.fysik.dtu.dk/ase/development/calculators.html
Copy link
Member

Choose a reason for hiding this comment

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

remove :

atoms = self._add_constraints(atoms)
constraints = atoms.constraints

ASECalculator.calculate(self, atoms, properties, system_changes)
Copy link
Member

Choose a reason for hiding this comment

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

use super


return forces

@decorator_convert_material_args_kwargs_to_atoms
Copy link
Member

Choose a reason for hiding this comment

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

No point of having this

implemented_properties = ["energy", "forces"]

def __init__(
self,
Copy link
Member

Choose a reason for hiding this comment

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

should have material_calculator as parameter


Args:
shadowing_radius (float): The radius for atom to shadow underlying from being considered surface, in Angstroms.
force_constant (float): The force constant for the finite difference approximation of the forces.
Copy link
Member

@timurbazhirov timurbazhirov Sep 14, 2024

Choose a reason for hiding this comment

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

Remove, this can be in interaction_function

@@ -120,3 +122,174 @@ def get_energy(
substrate_coordinates_values = np.array(substrate_surface_atom_coordinates.values)

return interaction_function(film_coordinates_values, substrate_coordinates_values)


class FixFilmRigidXY(BaseModel):
Copy link
Member

Choose a reason for hiding this comment

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

class InterfaceConstraint

class RigidFilmXYConstraint(InterfaceConstraint)

Base automatically changed from feature/SOF-7426 to main September 17, 2024 04:19
def _add_constraints(self, atoms: ASEAtoms) -> ASEAtoms:
constraints: List[Union[ASEFixAtoms, ASEFixedPlane, RigidFilmXYConstraint]] = []
if self.fix_substrate:
substrate_indices = [i for i, tag in enumerate(atoms.get_tags()) if tag == 0]
Copy link
Member

Choose a reason for hiding this comment

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

We should abstract this into get_interface_part_indices

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, but locally. Since it's ASE atoms, not Material

all_indices = list(range(len(atoms)))
constraints.append(ASEFixedPlane(indices=all_indices, direction=[0, 0, 1]))

film_indices = [i for i, tag in enumerate(atoms.get_tags()) if tag == 1]
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

@@ -120,3 +123,112 @@ def get_energy(
substrate_coordinates_values = np.array(substrate_surface_atom_coordinates.values)

return interaction_function(film_coordinates_values, substrate_coordinates_values)


class FilmSubstrateDistanceASECalculator(ASECalculator):
Copy link
Member

Choose a reason for hiding this comment

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

Let's put in ase subfolder for this and constraints into it

raise NotImplementedError


class RigidFilmXYConstraint(InterfaceConstraint):
Copy link
Member

Choose a reason for hiding this comment

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

InterfaceConstraint

@VsevolodX VsevolodX merged commit 7c090f6 into main Sep 19, 2024
9 checks passed
@VsevolodX VsevolodX deleted the feature/SOF-7427 branch September 19, 2024 02:52
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