pyiron_atomistics icon indicating copy to clipboard operation
pyiron_atomistics copied to clipboard

`calc_minimize(pressure=[0, 0, 0])` does not work for undefined structure

Open samwaseda opened this issue 2 years ago • 3 comments

lmp = pr.create.job.Lammps('lmp')
lmp.calc_minimize(pressure=[0, 0, 0])

This code raises the error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_37410/1534360834.py in <cell line: 2>()
      1 lmp = pr.create.job.Lammps('lmp_test')
----> 2 lmp.calc_minimize(pressure=[0, 0, 0])

~/dev_sam/pyiron_atomistics/pyiron_atomistics/lammps/interactive.py in calc_minimize(self, ionic_energy_tolerance, ionic_force_tolerance, e_tol, f_tol, max_iter, pressure, n_print, style)
    362                 "calc_minimize() is not implemented for the non modal interactive mode use calc_static()!"
    363             )
--> 364         super(LammpsInteractive, self).calc_minimize(
    365             ionic_energy_tolerance=ionic_energy_tolerance,
    366             ionic_force_tolerance=ionic_force_tolerance,

~/dev_sam/pyiron_atomistics/pyiron_atomistics/lammps/base.py in calc_minimize(self, ionic_energy_tolerance, ionic_force_tolerance, e_tol, f_tol, max_iter, pressure, n_print, style)
    769             n_print=n_print,
    770         )
--> 771         self.input.control.calc_minimize(
    772             ionic_energy_tolerance=ionic_energy_tolerance,
    773             ionic_force_tolerance=ionic_force_tolerance,

~/dev_sam/pyiron_atomistics/pyiron_atomistics/lammps/control.py in calc_minimize(self, ionic_energy_tolerance, ionic_force_tolerance, max_iter, pressure, n_print, style, rotation_matrix)
    248         if pressure is not None:
    249             self._force_skewed = False
--> 250             pressure = self.pressure_to_lammps(pressure, rotation_matrix)
    251             if np.isscalar(pressure):
    252                 str_press = " iso {}".format(pressure)

~/dev_sam/pyiron_atomistics/pyiron_atomistics/lammps/control.py in pressure_to_lammps(self, pressure, rotation_matrix)
    152         # Isotropic, hydrostatic pressures are rotation invariant.
    153         if not np.isclose(
--> 154             np.matrix.trace(rotation_matrix), 3
    155         ) and not self._is_isotropic_hydrostatic(pressure):
    156             if any(p is None for p in pressure):

TypeError: descriptor 'trace' for 'numpy.ndarray' objects doesn't apply to a 'NoneType' object

The problem simply comes from the fact that the rotation matrix is None, because there's no structure defined. Either we just live with the already existing warning (No structure set, can not validate the simulation cell!) or raise an error, but with a clearer message.

samwaseda avatar Aug 01 '22 18:08 samwaseda

Hello, I'd like to work on this issue! I'd propose raising a more descriptive error inside of the calc_minimize() method of the LammpsControl class if it is called with a rotation matrix of value None.

KuhnMn avatar Jan 16 '23 19:01 KuhnMn

Hi @KuhnMn, thanks for showing interest to contribute! I think simply raising a more descriptive error is fine for now. Since you have a good idea for the fix already, just go ahead and create a PR with that change.

pmrv avatar Jan 16 '23 23:01 pmrv

Hi, I created a PR but am having some trouble understanding the workflow issues. I left a more detailed comment on my PR on what exactly is happening. If it's not too big a circumstance, I'd really appreciate some help. Thanks in advance!

KuhnMn avatar Jan 18 '23 15:01 KuhnMn