<commit_before># coding: utf-8
# Copyright (c) Pymatgen Development Team.
# Distributed under the terms of the MIT License.

from __future__ import division, print_function, unicode_literals, absolute_import

"""
This module implements classes for generating/parsing Lammps data files.
"""

from six.moves import range
from io import open
import re
from collections import OrderedDict

import numpy as np

from monty.json import MSONable, MontyDecoder

from pymatgen.core.structure import Molecule, Structure

__author__ = '<NAME>'
__email__ = "<EMAIL>"


class LammpsData(MSONable):
    """
    Basic Lammps data: just the atoms section

    Args:
        box_size (list): [[x_min, x_max], [y_min,y_max], [z_min,z_max]]
        atomic_masses (list): [[atom type, mass],...]
        atoms_data (list): [[atom id, mol id, atom type, charge, x, y, z ...], ... ]
    """

    def __init__(self, box_size, atomic_masses, atoms_data):
        self.box_size = box_size
        self.natoms = len(atoms_data)
        self.natom_types = len(atomic_masses)
        self.atomic_masses = list(atomic_masses)
        self.atoms_data = atoms_data

    def __str__(self):
        """
        string representation of LammpsData

        Returns:
            String representation of the data file
        """
        lines = []
        lines.append("Data file generated by pymatgen\n")
        lines.append("{} atoms\n".format(self.natoms))
        lines.append("{} atom types\n".format(self.natom_types))
        lines.append("{} {} xlo xhi\n{} {} ylo yhi\n{} {} zlo zhi".format(
            self.box_size[0][0], self.box_size[0][1],
            self.box_size[1][0], self.box_size[1][1],
            self.box_size[2][0], self.box_size[2][1]))
        self.set_lines_from_list(lines, "Masses", self.atomic_masses)
        self.set_lines_from_list(lines, "Atoms", self.atoms_data)
        return '\n'.join(lines)

    @staticmethod
    def check_box_size(molecule, box_size):
        """
        Check the box size and if necessary translate the molecule so that
        all the sites are contained within the bounding box.

        Args:
            molecule(Molecule)
            box_size (list): [[x_min, x_max], [y_min, y_max], [z_min, z_max]]
        """
        x_min, y_min, z_min = np.min(molecule.cart_coords[:, 0]), \
                              np.min(molecule.cart_coords[:, 1]), \
                              np.min(molecule.cart_coords[:, 2])
        x_max, y_max, z_max = np.max(molecule.cart_coords[:, 0]), \
                              np.max(molecule.cart_coords[:, 1]), \
                              np.max(molecule.cart_coords[:, 2])
        box_lengths_req = [x_max - x_min,  y_max - y_min, z_max - z_min]
        box_lengths = [min_max[1] - min_max[0] for min_max in box_size]
        try:
            np.testing.assert_array_less(box_lengths_req, box_lengths)
        except AssertionError:
            print("Required box lengths {} larger than the provided box lengths{}. "
                  "Resetting the box size".format(box_lengths_req, box_lengths))
            box_size = [[0.0, i*1.1] for i in box_lengths_req]
        com = molecule.center_of_mass
        new_com = [(side[1] + side[0]) / 2 for side in box_size]
        translate_by = np.array(new_com) - np.array(com)
        molecule.translate_sites(range(len(molecule)), translate_by)
        return box_size

    def write_data_file(self, filename):
        """
        write lammps data input file from the string representation
        of the data.

        Args:<commit_msg>update the box size requirement setting<commit_after># coding: utf-8
# Copyright (c) Pymatgen Development Team.
# Distributed under the terms of the MIT License.

from __future__ import division, print_function, unicode_literals, absolute_import

"""
This module implements classes for generating/parsing Lammps data files.
"""

from six.moves import range
from io import open
import re
from collections import OrderedDict

import numpy as np

from monty.json import MSONable, MontyDecoder

from pymatgen.core.structure import Molecule, Structure

__author__ = '<NAME>'
__email__ = "<EMAIL>"


class LammpsData(MSONable):
    """
    Basic Lammps data: just the atoms section

    Args:
        box_size (list): [[x_min, x_max], [y_min,y_max], [z_min,z_max]]
        atomic_masses (list): [[atom type, mass],...]
        atoms_data (list): [[atom id, mol id, atom type, charge, x, y, z ...], ... ]
    """

    def __init__(self, box_size, atomic_masses, atoms_data):
        self.box_size = box_size
        self.natoms = len(atoms_data)
        self.natom_types = len(atomic_masses)
        self.atomic_masses = list(atomic_masses)
        self.atoms_data = atoms_data

    def __str__(self):
        """
        string representation of LammpsData

        Returns:
            String representation of the data file
        """
        lines = []
        lines.append("Data file generated by pymatgen\n")
        lines.append("{} atoms\n".format(self.natoms))
        lines.append("{} atom types\n".format(self.natom_types))
        lines.append("{} {} xlo xhi\n{} {} ylo yhi\n{} {} zlo zhi".format(
            self.box_size[0][0], self.box_size[0][1],
            self.box_size[1][0], self.box_size[1][1],
            self.box_size[2][0], self.box_size[2][1]))
        self.set_lines_from_list(lines, "Masses", self.atomic_masses)
        self.set_lines_from_list(lines, "Atoms", self.atoms_data)
        return '\n'.join(lines)

    @staticmethod
    def check_box_size(molecule, box_size):
        """
        Check the box size and if necessary translate the molecule so that
        all the sites are contained within the bounding box.

        Args:
            molecule(Molecule)
            box_size (list): [[x_min, x_max], [y_min, y_max], [z_min, z_max]]
        """
        box_lengths_req = [np.max(molecule.cart_coords[:, i])-np.min(molecule.cart_coords[:, i])
                           for i in range(3)]
        box_lengths = [min_max[1] - min_max[0] for min_max in box_size]
        try:
            np.testing.assert_array_less(box_lengths_req, box_lengths)
        except AssertionError:
            print("Required box lengths {} larger than the provided box lengths{}. "
                  "Resetting the box size".format(box_lengths_req, box_lengths))
            box_size = [[0.0, np.ceil(i*1.1)] for i in box_lengths_req]
        com = molecule.center_of_mass
        new_com = [(side[1] + side[0]) / 2 for side in box_size]
        translate_by = np.array(new_com) - np.array(com)
        molecule.translate_sites(range(len(molecule)), translate_by)
        return box_size

    def write_data_file(self, filename):
        """
        write lammps data input file from the string representation
        of the data.

        Args:
{'fraction_non_alphanumeric': 0.11662021417045622, 'fraction_numerical': 0.007481296758104738, 'mean_word_length': 2.549193128578865, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2236508', 'n_tokens_mistral': 2224, 'n_tokens_neox': 2171, 'n_words': 553}