This repository has been archived by the owner on Apr 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
main_conversion.py
executable file
·128 lines (101 loc) · 6.23 KB
/
main_conversion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from __future__ import print_function
import multiprocessing
import argparse
from multiprocessing import Pool
import numpy as np
import glob
import os
import re
import sys
import time
from write_lammps_data import lammps_inputs
from write_GULP_inputs import GULP_inputs
from UFF4MOF_construction import UFF4MOF
from UFF_construction import UFF
from Dreiding_construction import Dreiding
from zeoliteFFs_construction import MZHB
from ZIFFF_construction import ZIFFF
# add more force field classes here as they are made
def single_conversion(cif, force_field=UFF4MOF, ff_string='UFF4MOF', small_molecule_force_field=None,
outdir='unopt_lammps_data', charges=False, parallel=False, replication='1x1x1', read_cifs_pymatgen=False, add_molecule=None,
small_molecule_file=None):
print('converting ', cif, '...')
lammps_inputs([cif, force_field, ff_string, small_molecule_force_field, outdir, charges, replication, read_cifs_pymatgen, add_molecule, small_molecule_file])
def serial_conversion(directory, force_field=UFF4MOF, ff_string='UFF4MOF', small_molecule_force_field=None,
outdir='unopt_lammps_data', charges=False, parallel=False, replication='1x1x1', read_cifs_pymatgen=False, add_molecule=None,
small_molecule_file=None):
try:
os.mkdir(outdir)
except OSError:
pass
print('conversion running serial on a single core')
cifs = sorted(glob.glob(directory + os.sep + '*.cif'))
for cif in cifs:
print('converting ', cif, '...')
lammps_inputs([cif, force_field, ff_string, small_molecule_force_field, outdir, charges, replication, read_cifs_pymatgen, add_molecule, small_molecule_file])
print('--- cifs in', directory, 'converted and placed in', outdir, '---')
def parallel_conversion(directory, force_field=UFF4MOF, ff_string='UFF4MOF', small_molecule_force_field=None,
outdir='unopt_lammps_data', charges=False, parallel=True, replication='1x1x1', read_cifs_pymatgen=False, add_molecule=None,
small_molecule_file=None):
try:
os.mkdir(outdir)
except OSError:
pass
print('conversion running on ' + str(multiprocessing.cpu_count()) + ' cores')
cifs = sorted(glob.glob(directory + os.sep + '*.cif'))
args = [[cif, force_field, ff_string, small_molecule_force_field, outdir, charges, replication, read_cifs_pymatgen, add_molecule, small_molecule_file] for cif in cifs]
pool = Pool(multiprocessing.cpu_count())
results_par = pool.map_async(lammps_inputs, args)
pool.close()
pool.join()
print('--- cifs in', directory, 'converted and placed in', outdir, '---')
def parallel_GULP_conversion(directory, force_field=UFF4MOF, outdir='GULP_inputs', charges=False, parallel=True, replication='1x1x1', GULP=True, noautobond=True):
try:
os.mkdir(outdir)
except OSError:
pass
print('conversion running on ' + str(multiprocessing.cpu_count()) + ' cores')
cifs = sorted(glob.glob(directory + os.sep + '*.cif'))
args = [[cif, force_field, outdir, charges, replication, noautobond] for cif in cifs]
pool = Pool(multiprocessing.cpu_count())
results_par = pool.map_async(GULP_inputs, args)
pool.close()
pool.join()
print('--- cifs in', directory, 'converted and placed in', outdir, '---')
def run_conversion():
parser = argparse.ArgumentParser(description='Optional arguments for running cif2lammps')
parser.add_argument('--cifs', action='store', dest='directory', type=str, required=True, help='the cifs to convert')
parser.add_argument('--force_field', action='store', dest='ff_string', type=str, required=False, default='UFF4MOF', help='the force field to use')
parser.add_argument('--small_molecule_force_field', action='store', dest='sm_ff_string', type=str, required=False, default='TraPPE', help='the force field to use for small molecules')
parser.add_argument('--outdir', action='store', dest='outdir', type=str, required=False, default='unopt_lammps_data', help='where to write the lammps inputs')
parser.add_argument('--charges', action='store_true', dest='charges', required=False, default=False, help='switch on charges')
parser.add_argument('--replication', action='store', dest='replication', type=str, required=False, default='1x1x1', help='replications to use')
parser.add_argument('--GULP', action='store_true', dest='GULP', required=False, default=False, help='write GULP inputs instead of LAMMPS')
parser.add_argument('--parallel', action='store_true', dest='parallel', required=False, default=False, help='switch on parallel conversion')
parser.add_argument('--read_cifs_pymatgen', action='store_true', dest='read_cifs_pymatgen', required=False, default=False, help='use ASE to read CIF inputs')
parser.add_argument('--add_molecule', action='store', dest='add_molecule', required=False, default=None, help='name of a molecule to write molecule file for')
parser.add_argument('--small_molecule_file', action='store', dest='sm_file', type=str, required=False, default=None, help='a cif, xyz, or pdb of small molecules to be added, should be in cifs folder')
args = parser.parse_args()
print(args)
if args.add_molecule != None:
# should be name of molecule, model, number to add
add_molecule = args.add_molecule.split(', ')
add_molecule[2] = int(add_molecule[2])
else:
add_molecule = args.add_molecule
ff_dict = {'UFF4MOF':UFF4MOF, 'UFF':UFF, 'Dreiding':Dreiding, 'MZHB':MZHB, 'ZIFFF':ZIFFF}
force_field = ff_dict[args.ff_string]
optional_arguments = {'force_field':force_field, 'ff_string':args.ff_string, 'small_molecule_force_field':args.sm_ff_string,
'outdir':args.outdir, 'charges':args.charges, 'replication':args.replication, 'read_cifs_pymatgen':args.read_cifs_pymatgen,
'add_molecule':add_molecule, 'small_molecule_file': args.sm_file}
if args.GULP:
print('converting to GULP format...')
parallel_GULP_conversion(args.directory, **optional_arguments)
if args.parallel:
parallel_conversion(args.directory, **optional_arguments)
else:
serial_conversion(args.directory, **optional_arguments)
start_time = time.time()
if __name__ == '__main__':
run_conversion()
print("conversion took %s seconds " % np.round((time.time() - start_time), 3))