<commit_before># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import json
import pickle
import sys
from argparse import ArgumentParser
from contextlib import contextmanager
from socket import AF_INET, SOCK_STREAM, socket

from berny import Berny, geomlib

__all__ = ()


@contextmanager
def berny_unpickled(berny=None):
    picklefile = 'berny.pickle'
    if not berny:
        with open(picklefile, 'rb') as f:
            berny = pickle.load(f)
    try:
        yield berny
    except Exception:
        raise
    with open(picklefile, 'wb') as f:
        pickle.dump(berny, f)


def handler(berny, f):
    energy = float(next(f))
    gradients = [[float(x) for x in l.split()] for l in f if l.strip()]
    berny.send(energy, gradients)
    return next(berny)


def get_berny(args):
    geom = geomlib.load(sys.stdin, args.format)
    if args.paramfile:
        with open(args.paramfile) as f:
            params = json.load(f)
    else:
        params = None
    berny = Berny(geom, **params)
    next(berny)
    return berny

<commit_msg>fix cli with no param file<commit_after># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import json
import pickle
import sys
from argparse import ArgumentParser
from contextlib import contextmanager
from socket import AF_INET, SOCK_STREAM, socket

from berny import Berny, geomlib

__all__ = ()


@contextmanager
def berny_unpickled(berny=None):
    picklefile = 'berny.pickle'
    if not berny:
        with open(picklefile, 'rb') as f:
            berny = pickle.load(f)
    try:
        yield berny
    except Exception:
        raise
    with open(picklefile, 'wb') as f:
        pickle.dump(berny, f)


def handler(berny, f):
    energy = float(next(f))
    gradients = [[float(x) for x in l.split()] for l in f if l.strip()]
    berny.send(energy, gradients)
    return next(berny)


def get_berny(args):
    geom = geomlib.load(sys.stdin, args.format)
    if args.paramfile:
        with open(args.paramfile) as f:
            params = json.load(f)
    else:
        params = {}
    berny = Berny(geom, **params)
    next(berny)
    return berny


{'fraction_non_alphanumeric': 0.09754064193413922, 'fraction_numerical': 0.003334722801167153, 'mean_word_length': 2.8585209003215435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5676415', 'n_tokens_mistral': 831, 'n_tokens_neox': 807, 'n_words': 268}