From 8663962fcfc61105f6e52f268b69331532e91841 Mon Sep 17 00:00:00 2001 From: Adam Parler Date: Wed, 6 Dec 2023 02:37:36 -0800 Subject: [PATCH] Moved from C++ to C. Updated Python files. --- .gitignore | 7 +- src/basis/getlibr.py | 71 +++++++-- src/{nwchem.cpp => nwchem.c} | 6 +- src/rtdb/rtdb.h | 288 ++++++++++++++++++++++------------- src/tce/oce.py | 24 ++- src/tce/splitfiles.py | 17 +-- src/util/errquit.h | 6 +- 7 files changed, 270 insertions(+), 149 deletions(-) mode change 100644 => 100755 src/basis/getlibr.py rename src/{nwchem.cpp => nwchem.c} (99%) diff --git a/.gitignore b/.gitignore index 71319bc..0062803 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +.vscode +bin/ +build/ +include/ +lib/ ### C ### # Prerequisites @@ -19,7 +24,6 @@ *.gch *.pch - # Libraries *.dll *.so @@ -89,6 +93,7 @@ ehthumbs_vista.db # Folder config file Desktop.ini +.DS_Store # Recycle Bin used on file shares $RECYCLE.BIN/ diff --git a/src/basis/getlibr.py b/src/basis/getlibr.py old mode 100644 new mode 100755 index c5aefbf..e8ae321 --- a/src/basis/getlibr.py +++ b/src/basis/getlibr.py @@ -1,26 +1,35 @@ -#!/usr/bin/env python3 +#!/usr/bin/python3 # This script downloads the basis set library data from www.basissetexchange.org # into the directory $NWCHEM_TOP/src/basis/libraries.bse -# to use, set the env. variable NWCHEM_BASIS_LIBRARY=$NWCHEM_TOP/src/basis/libraries.bse/ +# To run, cd $NWCHEM_TOP/src/basis/libraries.bse/ && ../getlibr.py +# this will update the content of $NWCHEM_TOP/src/basis/libraries.bse +# To use the updates library, set the env. variable NWCHEM_BASIS_LIBRARY=$NWCHEM_TOP/src/basis/libraries.bse/ # Requires the installation of the python env. from # https://github.com/MolSSI-BSE/basis_set_exchange +# e.g. python3 -m pip install --user basis_set_exchange # See https://molssi-bse.github.io/basis_set_exchange/ # # names changed # def2-universal-jfit was weigend_coulomb_fitting # dgauss-a1-dftjfit was dgauss_a1_dft_coulomb_fitting # dgauss-a2-dftjfit was dgauss_a2_dft_coulomb_fitting -# + import basis_set_exchange as bse from datetime import datetime today = datetime.now().isoformat(timespec='minutes') print(today) all_bs = bse.get_all_basis_names() md = bse.get_metadata() -for bas_name in all_bs: - #get version and list of elements - version_bs = md[bas_name]['latest_version'] - elements_list = md[bas_name]['versions'][version_bs]['elements'] +summary_file = open('summary.txt','w') + +def writebs(md, bas_name, summary_file, get_aux=0): + md_bas_name = bas_name.lower() + md_bas_name = md_bas_name.replace("*","_st_") + md_bas_name = md_bas_name.replace("/","_sl_") + print(' md_bas_name '+md_bas_name+"\n") + print(' bas_name '+bas_name+"\n") + version_bs = md[md_bas_name]['latest_version'] + elements_list = md[md_bas_name]['versions'][version_bs]['elements'] #open file # get rid of asterisks file_name = bas_name.replace("*","s") @@ -33,19 +42,38 @@ for bas_name in all_bs: file_name = file_name.replace(" ","_") #replace forward slash with underscore file_name = file_name.replace("/","_") + #lowercase + file_name = file_name.lower() + if get_aux==1: + file_name = file_name + "-autoaux" print(' file name is '+file_name+"\n") output_file = open(file_name,'w') output_file.write('# BSE Version '+bse.version()+'\n') - output_file.write('# Data downloaded at '+today+'\n') - output_file.write('# '+bas_name+' version number '+version_bs+'\n') - output_file.write('# Description: '+md[bas_name]['description']+'\n') - output_file.write('# Role: '+md[bas_name]['role']+'\n') - output_file.write('# '+bse.get_references(bas_name,fmt='txt').replace('\n','\n# ')) - output_file.write('# \n') + output_file.write('# Data downloaded on '+today+'\n') + + if get_aux==0: + output_file.write('# '+bas_name+' version number '+version_bs+'\n') + output_file.write('# Description: '+md[md_bas_name]['description']+'\n') + output_file.write('# Role: '+md[md_bas_name]['role']+'\n') + output_file.write('# '+bse.get_references(bas_name,fmt='txt').replace('\n','\n# ')) + output_file.write('# \n') + elif get_aux==1: + output_file.write('# '+bas_name+' version number '+version_bs+' AutoAux \n') + output_file.write('# Role: JK Fitting \n') + output_file.write('# Stoychev GL, Auer AA, Neese F. \n# Automatic Generation of Auxiliary Basis Sets.\n# J Chem Theory Comput. 2017 Feb 14;13(2):554-562.\n# doi: 10.1021/acs.jctc.6b01041.\n') + output_file.write('# \n') + + n_elements=0 + for element in elements_list: + n_elements = n_elements + 1 + if get_aux==1: + summary_file.write('Basis set \"'+bas_name+'-autoaux\" (number of atoms '+str(n_elements)+')\n') + else: + summary_file.write('Basis set \"'+bas_name+'\" (number of atoms '+str(n_elements)+')\n') for element in elements_list: #element='h' try: - bs_str=bse.get_basis(bas_name, header=False, elements=element, fmt='nwchem', optimize_general=True, uncontract_general=True) + bs_str=bse.get_basis(bas_name, header=False, elements=element, fmt='nwchem', optimize_general=True, uncontract_general=True, get_aux=get_aux) except: # print("failed for"+element) pass @@ -54,11 +82,22 @@ for bas_name in all_bs: bs_str=bs_str.replace("END","end") bs_str=bs_str.replace("PRINT","") element_str=bse.misc.compact_elements([element]) - bs_str=bs_str.replace("ao basis",element_str+"_"+bas_name) + if get_aux==1: + bs_str=bs_str.replace("ao basis",element_str+"_"+bas_name+"-autoaux") + else: + bs_str=bs_str.replace("ao basis",element_str+"_"+bas_name) #ECP bs_str=bs_str.replace("ECP","ecp \""+element_str+"_"+bas_name+"\"") output_file.write(bs_str) # print(bas_name+" "+element_str) -print("end") + return +for bas_name in all_bs: + md_bas_name = bas_name.lower() + md_bas_name = md_bas_name.replace("*","_st_") + md_bas_name = md_bas_name.replace("/","_sl_") + writebs(md, bas_name, summary_file) + if md[md_bas_name]['role'] == 'orbital': + writebs(md, bas_name, summary_file, get_aux=1) +print("end") \ No newline at end of file diff --git a/src/nwchem.cpp b/src/nwchem.c similarity index 99% rename from src/nwchem.cpp rename to src/nwchem.c index 620af57..e98437a 100644 --- a/src/nwchem.cpp +++ b/src/nwchem.c @@ -265,7 +265,7 @@ int main(){ errquit('start: rtdb_open old failed', 0, RTDB_ERR); } } - + // initialize nxtask nxtask_init(rtdb); @@ -344,7 +344,7 @@ int main(){ errquit('control: rtdb_print failed', 0, RTDB_ERR); } } - + if (!rtdb_close(rtdb, 'keep')){ errquit('nwchem: rtdb_close failed', rtdb, RTDB_ERR); } @@ -372,7 +372,7 @@ int main(){ ga_print_stats(); write(LuOut,*); } - + } diff --git a/src/rtdb/rtdb.h b/src/rtdb/rtdb.h index c50f473..069b115 100644 --- a/src/rtdb/rtdb.h +++ b/src/rtdb/rtdb.h @@ -1,105 +1,183 @@ -// -// Header file for intial FORTRAN interface to RTDB -// (see the C header file rtdb.h for more detail) -// -// All functions return .TRUE. on success, .FALSE. on failure -// -// All functions are also mirrored by routines rtdb_* -> rtdb_par_* -// in which process 0 performs the operation and all other processes -// are broadcast the result of a read and discard writes. -// -// rtdb_max_key ... an integer parameter that defines the maximum -// length of a character string key -// -// rtdb_max_file ... an integer parameter that defines the maximum -// length of a file name -// -// -// logical function rtdb_parallel(mode) -// logical mode [input] -// -// -// logical function rtdb_open(filename, mode, handle) -// character *(*) filename [input] -// character *(*) mode [input] -// integer handle [output] -// -// logical function rtdb_clone(handle, suffix) -// integer handle [input] -// character*(*) suffix [input] -// -// logical function rtdb_close(handle, mode) -// integer handle [input] -// character*(*) mode [input] -// -// logical function rtdb_put(handle, name, ma_type, nelem, array) -// integer handle [input] -// character *(*) name [input] -// integer ma_type [input] -// integer nelem [input] -// array(nelem) [input] -// -// logical function rtdb_get_info(handle, name, ma_type, nelem, date) -// integer handle [input] -// character *(*) name [input] -// integer ma_type [output] -// integer nelem [output] -// character*26 date [output] -// -// logical function rtdb_get(handle, name, ma_type, nelem, array) -// integer handle [input] -// character *(*) name [input] -// integer ma_type [input] -// integer nelem [input] -// array(nelem) [output] -// -// logical function rtdb_ma_get(handle, name, ma_type, nelem, ma_handle) -// integer handle [input] -// character *(*) name [input] -// integer ma_type [output] -// integer nelem [output] -// integer ma_handle [output] -// -// logical function rtdb_cput(handle, name, nelem, buf) -// integer handle [input] -// character *(*) name [input] -// character *(*) buf [input] -// -// logical function rtdb_cget(handle, name, nelem, buf) -// integer handle [input] -// character *(*) name [input] -// character *(*) buf [output] -// -// logical function rtdb_print(handle, print_values) -// integer handle [input] -// logical print_values [input] -// -// logical function rtdb_first(handle, name) -// integer handle [input] -// character *(*) name [output] -// -// logical function rtdb_next(handle, name) -// integer handle [input] -// character *(*) name [output] -// -// logical function rtdb_delete(handle, name) -// integer handle [input] -// character *(*) name [input] -// -bool rtdb_open, rtdb_close, rtdb_put, rtdb_get, rtdb_ma_get, - rtdb_cput, rtdb_cget, rtdb_print, rtdb_get_info, - rtdb_first, rtdb_next, rtdb_delete, rtdb_parallel, - rtdb_clone,rtdb_getfname,rtdb_cget_size; -//$Id$ -extern rtdb_open, rtdb_close, rtdb_put, rtdb_get, rtdb_ma_get, - rtdb_cput, rtdb_cget, rtdb_print, rtdb_get_info, - rtdb_first, rtdb_next, rtdb_delete, rtdb_parallel, - rtdb_clone,rtdb_getfname,rtdb_cget_size; -// -// Check these values against rtdb_f2c.c -// -const int rtdb_max_key=255; -const int rtdb_max_file=255; -// -const bool rtdb_seq_mode = false; -const bool rtdb_par_mode = true; +#ifndef _RTDB_H +#define _RTDB_H + +/* + All routines return TRUE (1) on success, FALSE (0) on failure. + + int rtdb_parallel(const int mode) + + Set the parallel access mode of all databases to mode and + return the previous setting + + + int rtdb_open(const char *filename, const char *mode, int *handle) + + Filename = path to file associated with the data base + mode = 'new' Open only if it does not exist already + 'old', Open only if it does exist already + 'unknown' Create new or open existing (preserving contents) + 'empty' Create new or open existing (deleting contents) + 'scratch' Create new or open existing (deleting contents) + and automatically delete upon closing. Also, items + cached in memory are not written to disk. + + handle = returns handle by which all future references to the + data base are made + + + + int rtdb_clone(const int handle, const char *suffix) + + Copy the data base file + + handle = handle to RTDB + suffix + + + int rtdb_close(const int handle, const char *mode) + + Close the data base + + handle = handle to RTDB + mode = 'keep' Preserve the data base file to enable restart + 'delete' Delete the data base file freeing all resources + + mode is overridden by opening the data base with + mode='scratch' in which instance it is always deleted + upon closing + + + int rtdb_get_info(const int handle, const char *name, int *ma_type, + int *nelem, char date[26]) + + Get info about an entry from the data base + + handle = handle to RTDB + name = entry name (null terminated character string) + ma_type = returns MA type of the entry + nelem = returns no. of elements of the given type + date = returns date of insertion (null terminated character string) + + + int rtdb_put(const int handle, const char *name, const int ma_type, + const int nelem, const void *array) + + Insert an entry into the data base replacing previous entry + + handle = handle to RTDB + name = entry name (null terminated character string) + ma_type = MA type of the entry + nelem = no. of elements of the given type + array = data to be inserted + + + int rtdb_get(const int handle, const char *name, const int ma_type, + const int nelem, void *array) + + Get an entry from the data base + + handle = handle to RTDB + name = entry name (null terminated character string) + ma_type = MA type of the entry which must match entry type + nelem = size of array in units of ma_type + array = user provided buffer that returns data + + + int rtdb_ma_get(const int handle, const char *name, int *ma_type, + int *nelem, int *ma_handle) + + Get an entry from the data base returning an MA handle + + handle = handle to RTDB + name = entry name (null terminated character string) + ma_type = returns MA type of the entry + nelem = returns no. of elements of type ma_type in data + ma_handle= returns MA handle to data + + + int rtdb_first(const int handle, const int namelen, char *name) + + Return the name of the first (user inserted) entry in the data base. + The order is effectively random. + + handle = handle to RTDB + namelen = size of user provided buffer name + name = name of entry is returned in this buffer + + + int rtdb_next(const int handle, const int namelen, char *name) + + Return the name of the next (user inserted) entry in the data base. + The order is effectively random. + + handle = handle to RTDB + namelen = size of user provided buffer name + name = name of entry is returned in this buffer + + + int rtdb_print(const int handle, const int print_values) + + Print the contents of the data base to stdout + + handle = handle to RTDB + print_values = boolean flag ... if true values as well as + keys are printed out. + + + int rtdb_delete(const int handle, const char *name) + + Delete the entry from the database. + Return + 1 if key was present and successfully deleted + + 0 if key was not present, or if an error occured + + handle = handle to RTDB + name = name of entry to delete + +*/ + +int rtdb_open(const char *, const char *, int *); +int rtdb_clone(const int, const char *); +int rtdb_getfname(const int, char [36]); +int rtdb_close(const int, const char *); +int rtdb_put(const int, const char *, const int, const int, + const void *); +int rtdb_get(const int, const char *, const int, const int, + bool); +int rtdb_get_info(const int, const char *, int *, int *, char [26]); +int rtdb_ma_get(const int, const char *, int *, int *, int *); +int rtdb_first(const int, const int, char *); +int rtdb_next(const int, const int, char *); +int rtdb_print(const int, const int); +int rtdb_delete(const int, const char *); +int rtdb_parallel(const int); + +/* + Following are 'sequential' versions of the above + for internal use only +*/ + +int rtdb_seq_open(const char *, const char *, int *); +int rtdb_seq_copy(const int, const char *); +int rtdb_seq_getfname(const int, char [36]); +int rtdb_seq_close(const int, const char *); +int rtdb_seq_put(const int, const char *, const int, const int, + const void *); +int rtdb_seq_get(const int, const char *, const int, const int, + void *); +int rtdb_seq_get_info(const int, const char *, int *, int *, char [26]); +int rtdb_seq_ma_get(const int, const char *, int *, int *, int *); +int rtdb_seq_first(const int, const int, char *); +int rtdb_seq_next(const int, const int, char *); +int rtdb_seq_print(const int, const int); +int rtdb_seq_delete(const int, const char *); + +#define RTDB_SEQ_MODE 0 //* Sequential mode +#define RTDB_PAR_MODE 1 //* Parallel mode + +#if (defined(CRAY) || defined(WIN32)) &&!defined(__crayx1) &&!defined(__MINGW32__) +#include "rtdb.cray.h" +#endif + +#endif diff --git a/src/tce/oce.py b/src/tce/oce.py index bba8979..31e1e14 100644 --- a/src/tce/oce.py +++ b/src/tce/oce.py @@ -27,9 +27,9 @@ def stringtooperatorsequence(expression): """Converts a string to an operatorsequence object""" # Syntax of the string is rather loosely defined as: # (1) Numerical factor (with no permutation allowed) (optional), summation (optional), amplitudes (optional), normal ordered sequence, - # (2) Numerical factor can be an arithmatic expression such as (1.0/4.0), + # (2) Numerical factor can be an arithmetic expression such as (1.0/4.0), # (3) Summation starts with either "SUM" or "sum" followed by a parenthesis of indexes, - # (4) Indexes can be either in one-letter notation (a-h, A-H for virtuals, i-o, I-O for occupieds, p-z, P-Z for either, case matters) + # (4) Indexes can be either in one-letter notation (a-h, A-H for virtuals, i-o, I-O for occupieds, p-z, P-Z for either, case matters) # or in OCE notation (p1,p2 for virtuals, h3,h4 for occupieds, g5,g6 for either, no overlap in numbering) # (5) Amplitudes start with "t" or any name followed by a dagger ("+") indicating complex conjugate (optional) and a parenthesis of indexes, # (6) Normal ordered operator sequence must exist even when it is empty "{}". @@ -71,8 +71,7 @@ def stringtooperatorsequence(expression): elif (index[0] == "g"): newsequence.append(Operator("general",dagger,int(index[1:]))) else: - print("Syntax error: an operator not recognized") - stop + raise SyntaxError(" an operator not recognized") operatorlist = operatorlist + newsequence newsequences.append(newsequence) @@ -156,8 +155,7 @@ def stringtooperatorsequence(expression): summation.indexes.append(indexinthelist) break else: - print("syntax error") - stop + raise SyntaxError(" ") # get amplitudes remainder = string.split(remainder,")") @@ -221,8 +219,7 @@ def stringtooperatorsequence(expression): newamplitude.indexes.append(indexinthelist) break else: - print("syntax error") - stop + raise SyntaxError(" ") amplitudes.append(newamplitude) newoperatorsequence = OperatorSequence(numericalfactor,summation,amplitudes,newsequences) @@ -231,8 +228,7 @@ def stringtooperatorsequence(expression): def combinepermutations(one,two): """Connects two permutations of indexes""" if (len(one) != len(two)): - print("Internal error") - stop + raise SyntaxError(" ") three = [] for n in range(len(one)/2): three.append(one[n]) @@ -749,7 +745,7 @@ class Factor: raise RuntimeError("unrealistic factor") fraction = abs(int(1.0/coefficient)) if (1.0/float(fraction) != abs(coefficient)): - print(" !!! WARNING !!! inaccurate arithmatic") + print(" !!! WARNING !!! inaccurate arithmetic") if (fraction == 1): frac = "" else: @@ -1732,7 +1728,7 @@ class ListOperatorSequences: print("") for line in self.show(): print(line) - return "" + return"" def show(self): """Returns a human-friendly string of the content""" @@ -1813,7 +1809,7 @@ class ListOperatorSequences: # pick up a pair of operator sequences for nsequencea in range(len(self.list)): # if (verbose): -# print('processing ',nsequencea,' / ',range(len(self.list))) +# print 'processing ',nsequencea,' / ',range(len(self.list)) sequencea = self.list[nsequencea] for nsequenceb in range(len(self.list)): sequenceb = self.list[nsequenceb] @@ -1907,7 +1903,7 @@ class ListOperatorSequences: print(" ! Warning! a cyclic contraction is found") # self.simplifythree(verbose) self.simplifytwo(verbose) - # the followings do not seem to affect the result, yet it costs enormous memory & time + # the following do not seem to affect the result, yet it costs enormous memory & time # self.simplifyfour(1) self = copy.deepcopy(self.deletezero()) return self diff --git a/src/tce/splitfiles.py b/src/tce/splitfiles.py index 75613a3..66ebdb8 100644 --- a/src/tce/splitfiles.py +++ b/src/tce/splitfiles.py @@ -1,32 +1,31 @@ -#!/usr/bin/env python3 # Usage: python splitfiles.py < inputfile.F # (c) All rights reserved by Battelle & Pacific Northwest Nat'l Lab (2002) # $Id$ -import string -import copy import sys source = sys.stdin.readlines() if (not source): - print("Usage: python splitfiles.py < inputfile.F") + print("Usage: python splitfiles.py < inputfile.F") nfiles = 0 +filename = " " +filecontent = " " for line in source: - if (string.find(line,"SUBROUTINE") != -1): + if (line.find("SUBROUTINE") != -1): if (nfiles): - file = open(filename+".F","w") + file = open(filename+".F", "w") for newline in filecontent: file.write(newline) - filename = string.split(line[string.find(line,"SUBROUTINE")+11:],"(")[0] + filename = line[line.find("SUBROUTINE")+11:].split("(", 99999)[0] print(filename+".o\\") nfiles = nfiles + 1 filecontent = [line] else: filecontent.append(line) # don't forget to dump the last subroutine -file = open(filename+".F","w") +file = open(filename+".F", "w") for newline in filecontent: file.write(newline) -print("Number of files generated:",nfiles) +print("Number of files generated:", nfiles) diff --git a/src/util/errquit.h b/src/util/errquit.h index 9c86292..53cc291 100644 --- a/src/util/errquit.h +++ b/src/util/errquit.h @@ -1,6 +1,8 @@ +#ifndef _ERRQUIT_H +#define _ERRQUIT_H // UERR - Not yet assigned to a category // UNKNOWN_ERR - Not yet assigned to a category -// MEM_ERROR - Generic Memory error +// MEM_ERR - Generic Memory error // RTDB_ERR - Error in the Runtime Database // INPUT_ERR - Error resulting from inproper user input // CAPMIS_ERR - Features that have not been implemented yet @@ -31,3 +33,5 @@ const int DISK_ERR = 100; const int CALC_ERR = 110; const int FMM_ERR = 120; // $Id$ + +#endif