<commit_before>import numpy as np
import shutil
import os
import mdtraj as md
from mdtraj.utils import enter_temp_directory
import tempfile

HEADER_TEMPLATE = """
# Mixture 

tolerance %f
filetype pdb
output %s
add_amber_ter

"""

BOX_TEMPLATE = """
structure %s
  number %d 
  inside box 0. 0. 0. %f %f %f
end structure
"""

def pack_box(pdb_filenames, n_molecules_list, tolerance=2.0, box_size=40.):
    """Run packmol to generate a box containing a mixture of molecules.

    Parameters
    ----------
    pdb_filenames : list(str)
        List of pdb filenames for each component of mixture.
    n_molecules_list : list(int)
        The number of molecules of each mixture component.
    tolerance : float, optional, default=2.0
        The mininum spacing between molecules during packing.  In ANGSTROMS!
    box_size : float, optional, default=40.0
        The size of the box to generate.  In ANGSTROMS.

    Returns
    -------
    trj : MDTraj.Trajectory
        Single frame trajectory with mixture box.

    Notes
    -----
    Be aware that MDTraj uses nanometers internally, but packmol uses angstrom
    units.  The present function takes `tolerance` and `box_size` in 
    angstrom units, but the output trajectory will have data in nm.  
    Also note that OpenMM is pretty picky about the format of unit cell input, 
    so use the example below to ensure that you do the right thing.
    
    Examples
    --------
    >>> trj = gaff2xml.packmol.pack_box(["./monomer.pdb"], [100])
    >>> xyz = trj.openmm_positions(0)
    >>> top = trj.top.to_openmm()
    >>> top.setUnitCellDimensions(mm.Vec3(*trj.unitcell_lengths[0]) * u.nanometer)

    """    
    assert len(pdb_filenames) == len(n_molecules_list), "Must input same number of pdb filenames as num molecules"
    
    output_filename = tempfile.mktemp(suffix=".pdb")
    
    header = HEADER_TEMPLATE % (tolerance, output_filename)
    for k in range(len(pdb_filenames)):
        filename = pdb_filenames[k]
        n_molecules = n_molecules_list[k]
        header = header + BOX_TEMPLATE % (filename, n_molecules, box_size, box_size, box_size)
    
    pwd = os.getcwd()
    
    print(header)
    
    packmol_filename = "packmol_input.txt"
    packmol_filename = tempfile.mktemp(suffix=".txt")
    
    file_handle = open(packmol_filename, 'w')<commit_msg>Fixed some doc<commit_after>import numpy as np
import shutil
import os
import mdtraj as md
from mdtraj.utils import enter_temp_directory
import tempfile

HEADER_TEMPLATE = """
# Mixture 

tolerance %f
filetype pdb
output %s
add_amber_ter

"""

BOX_TEMPLATE = """
structure %s
  number %d 
  inside box 0. 0. 0. %f %f %f
end structure
"""

def pack_box(pdb_filenames, n_molecules_list, tolerance=2.0, box_size=40.):
    """Run packmol to generate a box containing a mixture of molecules.

    Parameters
    ----------
    pdb_filenames : list(str)
        List of pdb filenames for each component of mixture.
    n_molecules_list : list(int)
        The number of molecules of each mixture component.
    tolerance : float, optional, default=2.0
        The mininum spacing between molecules during packing.  In ANGSTROMS!
    box_size : float, optional, default=40.0
        The size of the box to generate.  In ANGSTROMS.

    Returns
    -------
    trj : MDTraj.Trajectory
        Single frame trajectory with mixture box.

    Notes
    -----
    Be aware that MDTraj uses nanometers internally, but packmol uses angstrom
    units.  The present function takes `tolerance` and `box_size` in 
    angstrom units, but the output trajectory will have data in nm.  
    Also note that OpenMM is pretty picky about the format of unit cell input, 
    so use the example below to ensure that you do the right thing.
    
    Examples
    --------
    >>> import gaff2xml
    >>> pdb_filename = gaff2xml.utils.get_data_filename("chemicals/benzene/benzene.pdb")
    >>> trj = gaff2xml.packmol.pack_box([pdb_filename], [100])
    >>> xyz = trj.openmm_positions(0)
    >>> top = trj.top.to_openmm()
    >>> top.setUnitCellDimensions(mm.Vec3(*trj.unitcell_lengths[0]) * u.nanometer)

    """    
    assert len(pdb_filenames) == len(n_molecules_list), "Must input same number of pdb filenames as num molecules"
    
    output_filename = tempfile.mktemp(suffix=".pdb")
    
    header = HEADER_TEMPLATE % (tolerance, output_filename)
    for k in range(len(pdb_filenames)):
        filename = pdb_filenames[k]
        n_molecules = n_molecules_list[k]
        header = header + BOX_TEMPLATE % (filename, n_molecules, box_size, box_size, box_size)
    
    pwd = os.getcwd()
    
    print(header)
    
    packmol_filename = "packmol_input.txt"
    packmol_filename = tempfile.mktemp(suffix=".txt")
    
    file_handle = open(packmol_filename, 'w')
{'fraction_non_alphanumeric': 0.09654450261780105, 'fraction_numerical': 0.008376963350785341, 'mean_word_length': 2.98, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '308604', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1530, 'n_words': 463}