def test_atoms_load__loads_lmpdat_from_file_or_path(): with Path("tests/uio66/uio66-linker.lmpdat") as path: atoms = Atoms.load(path, atom_format="atomic") assert len(atoms) == 16 with Path("tests/uio66/uio66-linker.lmpdat").open() as fd: atoms = Atoms.load(fd, filetype="lmpdat", atom_format="atomic") assert len(atoms) == 16
def test_atoms_load__loads_cif_from_file_or_path(): with Path("tests/uio66/uio66-linker.cif") as path: atoms = Atoms.load(path) assert len(atoms) == 16 with Path("tests/uio66/uio66-linker.cif").open() as fd: atoms = Atoms.load(fd, filetype="cif") assert len(atoms) == 16
import csv import sys import time import numpy as np from mofun import Atoms, replace_pattern_in_structure, find_pattern_in_structure all_repldims = [(1, 1, 1), (2, 2, 2)] # all_repldims = [(1,1,1), (2,2,2), (4,4,4)] # all_repldims = [(1,1,1), (2,2,2), (4,4,4), (8,8,8)] uio66 = Atoms.load("uio66.cif") uio67 = Atoms.load("uio67.cif") uio66_linker = Atoms.load("uio66-linker.cml") uio67_linker = Atoms.load("uio67-linker.cml") output_csv = csv.writer(sys.stdout) output_csv.writerow([ "mof", "repl", "num-atoms", "matches-found", "matches-expected", "process-time-seconds", "perf-counter-seconds" ]) for repldims in all_repldims: structure = uio66.replicate(repldims=repldims) time_s = time.process_time() perf_s = time.perf_counter() patterns = find_pattern_in_structure(structure, uio66_linker) output_csv.writerow( ("uio66", "%dx%dx%dx" % repldims, len(structure),
def mofun_cli(inputpath, outputpath, find_path=None, replace_path=None, replace_fraction=1.0, axis1a_idx=0, axis1b_idx=-1, axis2_idx=None, dumppath=None, chargefile=None, replicate=None, mic=None, framework_element=None, pp=False): atoms = Atoms.load(inputpath) # upate positions from lammps dump file if dumppath is not None: # update positions in original atoms file with new positions dumpatoms = ase.io.read(dumppath, format="lammps-dump-text") assert len(dumpatoms.positions) == len(atoms.positions) atoms.positions = dumpatoms.positions # update charges if chargefile is not None: charges = np.array( [float(line.strip()) for line in chargefile if line.strip() != '']) assert len(charges) == len(atoms.positions) atoms.charges = charges if replicate is not None: atoms = atoms.replicate(replicate) # replicate to meet minimum image convention, if necessary if mic is not None: repls = np.array(np.ceil(2 * mic / np.diag(atoms.cell)), dtype=int) atoms = atoms.replicate(repls) if pp: assign_pair_params_to_structure(atoms) if replace_path is not None and find_path is None: print("Cannot perform a replace operation without a find operation") elif find_path is not None: search_pattern = Atoms.load(find_path) if replace_path is not None: replace_pattern = Atoms.load(replace_path) atoms = replace_pattern_in_structure( atoms, search_pattern, replace_pattern, axis1a_idx=axis1a_idx, axis1b_idx=axis1b_idx, axis2_idx=axis2_idx, replace_fraction=replace_fraction) else: results = find_pattern_in_structure(atoms, search_pattern) print("Found %d instances of the search_pattern in the structure" % len(results)) print(results) # set framework elements to specified element-only works on ASE exports if framework_element is not None: atoms.symbols[atoms.atom_groups == 0] = framework_element if outputpath.suffix in ['.lmpdat', '.mol']: atoms.save(outputpath) else: print("INFO: Trying output using ASE") aseatoms = atoms.to_ase() if framework_element is not None: aseatoms.symbols[atoms.atom_groups == 0] = framework_element aseatoms.set_pbc(True) aseatoms.write(outputpath)