librascal icon indicating copy to clipboard operation
librascal copied to clipboard

sanitize_non_periodic_structure does not update the lattice vectors of the cell

Open bananenpampe opened this issue 2 years ago • 0 comments

Heyhey, I don't know, if this function is still in use, but: The helperfunction rascal.neighbourlist.structure_manager.sanitize_non_periodic_structure is intended to wrap nonperiodic structures and calculate lattice cell vectors for a unit cell that wraps up the whole molecule, but then does not update the cell parameters.

    def sanitize_non_periodic_structure(structure):
    """
    Rascal expects a unit cell that contains all the atoms even if the
    structure is not periodic.
    If the cell is set to 0 and the structure is not periodic then it
    is adapted to contain the atoms and the atoms are shifted inside the unit
    cell.
    Parameters
    ----------
    structure : a valid structure as per is_valid_structure
    Returns
    -------
    a valid structure as per is_valid_structure
        cell and positions have been modified if structure is not periodic
    """

    if np.all(structure["pbc"] == 0):
        cell = structure["cell"]
        if np.allclose(cell, np.zeros((3, 3))):
            pos = structure["positions"]
            bounds = np.array([pos.min(axis=1), pos.max(axis=1)])
            bounding_box_lengths = (bounds[1] - bounds[0]) * 1.05
            print(bounding_box_lengths)
            new_cell = np.diag(bounding_box_lengths)
            CoM = pos.mean(axis=1)
            disp = 0.5 * bounding_box_lengths - CoM
            new_pos = pos + disp[:, None]
            structure["positions"] = new_pos
            #update cell parameters here
    return structure

bananenpampe avatar Jul 13 '22 15:07 bananenpampe