Skip to content

Commit

Permalink
fix: rewrite gaussian files
Browse files Browse the repository at this point in the history
  • Loading branch information
njzjz committed Jul 7, 2019
1 parent d375931 commit fa0155b
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions mddatasetbuilder/datasetbuilder.py
Expand Up @@ -46,7 +46,7 @@ def __init__(
clusteratom=None, bondfilename=None,
dumpfilename="dump.reaxc", dataset_name="md", cutoff=5,
stepinterval=1, n_clusters=10000,
qmkeywords="%nproc=4\n#mn15/6-31g(d,p)", nproc=None, pbc=True,
qmkeywords="%nproc=4\n#mn15/6-31g(d,p) force", nproc=None, pbc=True,
fragment=True, errorfilename=None, errorlimit=0.):
"""Init the builder."""
print(__doc__)
Expand All @@ -72,6 +72,8 @@ def __init__(
self.writegjf = True
self.gjfdir = f'{self.dataset_dir}_gjf'
self.qmkeywords = qmkeywords
if type(self.qmkeywords) == str:
self.qmkeywords = [self.qmkeywords]
self.fragment = fragment
self._coulumbdiag = dict(map(lambda symbol: (
symbol, atomic_numbers[symbol]**2.4/2), atomname))
Expand Down Expand Up @@ -292,31 +294,30 @@ def _convertgjf(self, gjffilename, takenatomidindex, atoms_whole):
multiplicities = list(map(lambda atoms: (3 if atoms_whole[atoms].get_chemical_symbols() == [
"O", "O"] else(Counter(atoms_whole[atoms].get_chemical_symbols())['H'] % 2 + 1)), takenatomidindex))
multiplicity_whole = sum(multiplicities)-len(takenatomidindex)+1
title = '\nGenerated by MDDatasetMaker\n'
multiplicity_whole_str = f'0 {multiplicity_whole}'
qmkeywords = self.qmkeywords
title = '\nGenerated by MDDatasetMaker (Author: Jinzhe Zeng)\n'
if len(qmkeywords) > 1:
connect = '\n--link1--\n'
chk = [f'%chk={os.path.splitext(os.path.basename(gjffilename))[0]}.chk']
else:
chk = []
if len(takenatomidindex) == 1 or not self.fragment:
buff.extend((self.qmkeywords, title))
buff.append(f'0 {multiplicity_whole}')
buff.extend((*chk, qmkeywords[0], title, multiplicity_whole_str))
buff.extend(map(lambda atom: "{} {:.5f} {:.5f} {:.5f}".format(
atom.symbol, *atom.position), atoms_whole))
buff.append('\n')
else:
chk = f'%chk={os.path.splitext(os.path.basename(gjffilename))[0]}.chk'
connect = '\n--link1--\n'
kw1 = f'{self.qmkeywords} guess=fragment={len(takenatomidindex)}'
kw2 = f'{self.qmkeywords} force geom=chk guess=read'
multiplicities_str = ' '.join(
map(
lambda
multiplicity: f'0 {multiplicity}',
itertools.chain(
(multiplicity_whole,),
multiplicities)))
buff.extend((chk, kw1, title, multiplicities_str))
qmkeywords[0] = f'{qmkeywords[0]} guess=fragment={len(takenatomidindex)}'
multiplicities_str = multiplicity_whole_str + ' '.join(
[f'0 {multiplicity}' for multiplicity in multiplicities])
buff.extend((*chk, qmkeywords[0], title, multiplicities_str))
for index, atoms in enumerate(takenatomidindex, 1):
buff.extend(map(lambda atom: '{}(Fragment={}) {:.5f} {:.5f} {:.5f}'.format(
atom.symbol, index, *atom.position), atoms_whole[atoms]))
buff.extend((connect, chk, kw2,
title, multiplicities_str, '\n'))
for kw in itertools.islice(qmkeywords, 1, None):
buff.extend((connect, *chk, kw,
title, f'0 {multiplicity_whole}', '\n'))
buff.append('\n')
with open(gjffilename, 'w') as f:
f.write('\n'.join(buff))

Expand Down

0 comments on commit fa0155b

Please sign in to comment.