<commit_before>#!/usr/bin/env python

"""
Molecular Dynamics Simulation of a System.
System must have been prepared with GROMACS, using the CHARMM36 FF, solvated
and neutralized, but not minimized (not necessarily at least).

.2017. <EMAIL>
"""

from __future__ import print_function, division

import argparse
import logging
import os
import random
import sys

import simtk.openmm.app as app
import simtk.openmm as mm
import simtk.unit as units

##
# Parse user input and options
ap = argparse.ArgumentParser(description=__doc__)

# Mandatory
ap.add_argument('gro', help='Input coordinates file (.gro)')
ap.add_argument('top', help='Input topology file (.top)')

# Output Options
out_opts = ap.add_argument_group('Output Options')
out_opts.add_argument('--log', type=str, help='Log file name')

# Sim Options
sim_opts = ap.add_argument_group('Simulation Options')
gmx_top = os.path.join(os.getenv('GMXDATA') or '', 'top')
sim_opts.add_argument('--ffdir', default=gmx_top,
                      help='GROMACS top/ folder [default: {}]'.format(gmx_top))
sim_opts.add_argument('--seed', type=int, default=917,
                      help='Random Number Seed [default: 917]')
sim_opts.add_argument('--restart', action='store_true',
                      help='Ignores any Checkpoint files in the folder.')

sim_opts.add_argument('--equilibration', type=float, default=5.0,
                      help='Time in ns for equilibration [default: 5.0]')
sim_opts.add_argument('--production', type=float, default=10.0,
                      help='Time in ns for production [default: 10.0]')

opt_plat = ap.add_mutually_exclusive_group()
opt_plat.add_argument('--cpu', action="store_true", help='Use CPU platform')
opt_plat.add_argument('--cuda', action="store_true", help='Use CUDA platform')
ap.set_defaults(cpu=False, cuda=True)

user_args = ap.parse_args()

# Set random seed for all Python processed (integrators too, further below)
random.seed(user_args.seed)

# Format logger
if not user_args.log:
    logfile = sys.stdout
else:
    logfile = open(user_args.log, 'w')

logging.basicConfig(stream=logfile,
                    level=logging.INFO,
                    format='[%(asctime)s] %(message)s',
                    datefmt='%Y/%m/%d %H:%M:%S')

logging.info('Starting Simulation')

# Define platform: CPU/CUDA
gpu_res = os.getenv('CUDA_VISIBLE_DEVICES')
cpu_res = os.getenv('SLURM_NTASKS')
properties = {}
if user_args.cuda:
    if not gpu_res:
        logging.error('No CUDA GPUs detected')
        sys.exit(1)

    platform = mm.Platform.getPlatformByName('CUDA')

    num_gpu = len(gpu_res.split(','))
    if num_gpu == 1:
        properties = {}
    else:
        logging.info('Using {}/{} CPUs/GPUs'.format(cpu_res, num_gpu))
        properties['DeviceIndex'] = gpu_res
else:
    platform = mm.Platform.getPlatformByName('CPU')
    properties['Threads'] = cpu_res

logging.info('Using platform: {}'.format(platform.getName()))
<commit_msg>Fixed env variable to get no. of CPUs on node<commit_after>#!/usr/bin/env python

"""
Molecular Dynamics Simulation of a System.
System must have been prepared with GROMACS, using the CHARMM36 FF, solvated
and neutralized, but not minimized (not necessarily at least).

.2017. <EMAIL>
"""

from __future__ import print_function, division

import argparse
import logging
import os
import random
import sys

import simtk.openmm.app as app
import simtk.openmm as mm
import simtk.unit as units

##
# Parse user input and options
ap = argparse.ArgumentParser(description=__doc__)

# Mandatory
ap.add_argument('gro', help='Input coordinates file (.gro)')
ap.add_argument('top', help='Input topology file (.top)')

# Output Options
out_opts = ap.add_argument_group('Output Options')
out_opts.add_argument('--log', type=str, help='Log file name')

# Sim Options
sim_opts = ap.add_argument_group('Simulation Options')
gmx_top = os.path.join(os.getenv('GMXDATA') or '', 'top')
sim_opts.add_argument('--ffdir', default=gmx_top,
                      help='GROMACS top/ folder [default: {}]'.format(gmx_top))
sim_opts.add_argument('--seed', type=int, default=917,
                      help='Random Number Seed [default: 917]')
sim_opts.add_argument('--restart', action='store_true',
                      help='Ignores any Checkpoint files in the folder.')

sim_opts.add_argument('--equilibration', type=float, default=5.0,
                      help='Time in ns for equilibration [default: 5.0]')
sim_opts.add_argument('--production', type=float, default=10.0,
                      help='Time in ns for production [default: 10.0]')

opt_plat = ap.add_mutually_exclusive_group()
opt_plat.add_argument('--cpu', action="store_true", help='Use CPU platform')
opt_plat.add_argument('--cuda', action="store_true", help='Use CUDA platform')
ap.set_defaults(cpu=False, cuda=True)

user_args = ap.parse_args()

# Set random seed for all Python processed (integrators too, further below)
random.seed(user_args.seed)

# Format logger
if not user_args.log:
    logfile = sys.stdout
else:
    logfile = open(user_args.log, 'w')

logging.basicConfig(stream=logfile,
                    level=logging.INFO,
                    format='[%(asctime)s] %(message)s',
                    datefmt='%Y/%m/%d %H:%M:%S')

logging.info('Starting Simulation')

# Define platform: CPU/CUDA
gpu_res = os.getenv('CUDA_VISIBLE_DEVICES')
cpu_res = os.getenv('SLURM_CPUS_PER_TASK')
properties = {}
if user_args.cuda:
    if not gpu_res:
        logging.error('No CUDA GPUs detected')
        sys.exit(1)

    platform = mm.Platform.getPlatformByName('CUDA')

    num_gpu = len(gpu_res.split(','))
    if num_gpu == 1:
        properties = {}
    else:
        logging.info('Using {}/{} CPUs/GPUs'.format(cpu_res, num_gpu))
        properties['DeviceIndex'] = gpu_res
else:
    platform = mm.Platform.getPlatformByName('CPU')
    properties['Threads'] = cpu_res

logging.info('Using platform: {}'.format(platform.getName()))

{'fraction_non_alphanumeric': 0.13615657162139364, 'fraction_numerical': 0.008098532141049435, 'mean_word_length': 3.8391836734693876, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5153063', 'n_tokens_mistral': 1982, 'n_tokens_neox': 1899, 'n_words': 461}