Skip to content

issue with pressure to lammps #301

@Atilaac

Description

@Atilaac

Since I did not had write access to the code to create a pull request to fix this issue with pressure conversion to lammps, I open this issue to address the problem.

the fix is adding these lines

if rotation_matrix is None:
        rotation_matrix = np.eye(3)

in the function _pressure_to_lammps found inside calculate.py. This solved the issue locally on my machine.

The issue is caused by an implicit assumption in _pressure_to_lammps() that a valid rotation_matrix is always provided when non-scalar pressure is passed. This have led to a crash in the simulation using shik potential when the pressure is needed to be ramped from 0.1 to 0 GPa. As when a pressure ramp is requested using a list, e.g. pressure=[0.1, 0.0], pyiron correctly interprets this as a non-scalar pressure specification and routes it through _pressure_to_lammps(). Inside this function, the code unconditionally evaluates trace(rotation_matrix) using the np.matrix.trace(rotation_matrix).

This this made me to trace this problem to a missing initialzation of rotation_matrix. Correct me if I am wrong.

Part of the error is shown below:

File /opt/homebrew/lib/python3.12/site-packages/pyiron_lammps/compatibility/calculate.py:125, in calc_md(temperature, pressure, time_step, n_print, temperature_damping_timescale, pressure_damping_timescale, seed, tloop, initial_temperature, langevin, delta_temp, delta_press, rotation_matrix, units) 120 raise ValueError( 121 "Target temperature for fix nvt/npt/nph cannot be 0 or negative" 122 ) 124 force_skewed = False --> 125 pressure = _pressure_to_lammps( 126 pressure=pressure, rotation_matrix=rotation_matrix, units=units 127 ) 129 if np.isscalar(pressure): 130 pressure_string = " iso {0} {0} {1}".format( 131 pressure, pressure_damping_timescale 132 ) File /opt/homebrew/lib/python3.12/site-packages/pyiron_lammps/compatibility/calculate.py:407, in _pressure_to_lammps(pressure, rotation_matrix, units) 402 raise ValueError("Pressure cannot have a length but all be None") 404 # If necessary, rotate the pressure tensor to the Lammps coordinate frame. 405 # Isotropic, hydrostatic pressures are rotation invariant. 406 if not np.isclose( --> 407 np.matrix.trace(rotation_matrix), 3 408 ) and not _is_isotropic_hydrostatic(pressure): 409 if any(p is None for p in pressure): 410 raise ValueError( 411 "Cells which are not orthorhombic or an upper-triangular cell are incompatible with Lammps " 412 "constant pressure calculations unless the entire pressure tensor is defined. " (...) 416 "its components is None." 417 ) TypeError: descriptor 'trace' for 'numpy.ndarray' objects doesn't apply to a 'NoneType' object

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions