Merge pull request #1 from bigperm17/development #1

Merged
aparler merged 1 commit from :main into main 2026-05-28 00:39:31 -04:00
6 changed files with 2910 additions and 0 deletions

64
src/basis/getlibr.py Normal file
View file

@ -0,0 +1,64 @@
#!/usr/bin/env 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/
# Requires the installation of the python env. from
# https://github.com/MolSSI-BSE/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']
#open file
# get rid of asterisks
file_name = bas_name.replace("*","s")
#get rid of parenthesis
file_name = file_name.replace("(","")
file_name = file_name.replace(")","")
#replace commas with underscore
file_name = file_name.replace(",","_")
#replace whitespace with underscore
file_name = file_name.replace(" ","_")
#replace forward slash with underscore
file_name = file_name.replace("/","_")
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')
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)
except:
# print("failed for"+element)
pass
else:
bs_str=bs_str.replace("BASIS","basis")
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)
#ECP
bs_str=bs_str.replace("ECP","ecp \""+element_str+"_"+bas_name+"\"")
output_file.write(bs_str)
#
print(bas_name+" "+element_str)
print("end")

403
src/nwchem.cpp Normal file
View file

@ -0,0 +1,403 @@
#include <stdint.h>
#include <stdio.h>
#include "errquit.h"
#include "rtdb.h"
#ifdef USE_TCGMSG
#include "tcgmsg.h"
#else
int NODEID;
extern NODEID;
#endif
#include "pstat.h"
#include "util.h"
#include "inp.h"
#include "bgj_common.h"
#include "stdio.h"
int RTDB;
int STACK;
int HEAP;
int GLOBAL;
bool STATUS;
bool OVERIFY, OHARDFAIL;
#ifdef CRAY_T3D
int oldact, fsigctl;
#endif
#ifdef PSCALE
int IO_CODE;
#else
int32_t IO_CODE;
#endif
// $Id$
// ======================================================================================================
//> \mainpage Northwest Computational Chemistry Package (NWChem) 7.0.2
//>
//> NWChem is an open-source computational chemistry package distributed under the terms of
//> the Educational Community License (ECL) 2.0
//>
//> This software and its documentation were developed at the EMSL at Pacific Northwest National Laboratory,
//> a multiprogram national laboratory, operated for the U.S. Department of Energy by Battelle under
//> Contract Number DE-AC05-76RL01830. Support for this work was provided by the Department of Energy
//> Office of Biological and Environmental Research, Office of Basic Energy Science, and the Office of
//> Advanced Scientific Computing.
//>
//> Licensed under the Educational Community License, Version 2.0 (the "License"); you may
//> not use this file except in compliance with the License. You may obtain a copy of the
//> License at <a href="https://opensource.org/licenses/ECL-2.0">https://opensource.org/licenses/ECL-2.0</a>.
//>
//> Unless required by applicable law or agreed to in writing, software distributed under the
//> License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
//> either express or implied. See the License for the specific language governing
//> permissions and limitations under the License.
//>
//> Further information, including user documentation and forums, may be found at
//> <a href="http://www.nwchem-sw.org/">http://www.nwchem-sw.org/</a>. Alternatively,
//> the paper
//>
//> * M. Valiev, E.J. Bylaska, N. Govind, K. Kowalski, T.P. Straatsma, H.J.J. Van Dam,
//> D. Wang, J. Nieplocha, E. Apra, T.L. Windus, W.A. de Jong (2010)<br>
//> "NWChem: A comprehensive and scalable open-source solution for large scale molecular simulations"<br>
//> <I>Computer Physics Communications</I>, <b>181</b>, 14771489, DOI: <a href="https://doi.org/10.1016/j.cpc.2010.04.018">10.1016/j.cpc.2010.04.018</a>
//>
//> provides details on the codes capabilities.
//>
//> Copyright (c) 1994-2020 Pacific Northwest National Laboratory, Battelle Memorial Institute
//>
//> Environmental Molecular Sciences Laboratory (EMSL)<br>
//> Pacific Northwest National Laboratory<br>
//> Richland, WA 99352
// ======================================================================================================
int main(){
char input_filename[nw_max_path_len], rtdb_name[nw_max_path_len];
double total_wall, total_cpu;
#ifdef USE_OFFLOAD
int ppnout;
bool offload_enabled;
extern offload_enabled;
int offload_device;
extern offload_device;
#endif
bool ostartup, ocontinue, orestart;
bool input_parse;
extern input_parse;
#if defined(USE_OPENMP)
int omp_get_max_threads;
extern omp_get_max_threads;
#endif
// Create parallel processes and initialize IPC layer
pbeginf();
// MXINIT is needed by PeIGS and PFFT to initialize
// the communication fabric they use.
mxinit();
// Initialize timers so they are relative to job start
total_wall = -util_wallsec();
total_cpu = -util_cpusec();
// Only process 0 opens the input file
// (note that ga_nodeid() does not work yet!)
if (nodeid() == 0){
// Get the name of the input file from the command line
get_input_filename(input_filename);
try {
FILE * LuIn = fopen(input_filename,'r');
}
catch {
errquit('nwchem: failed to open the input file', 0, INPUT_ERR);
}
}
else{
#if !(defined(KSR) || defined(IBM) || defined(FUJITSU_SOLARIS) ||defined(FUJITSU_VPP) ||defined(FUJITSU_VPP64))
fclose(LuIn);
#endif
}
// Look for memory directive in the input ... must eventually
// open the rtdb first so that can get memory directive out of that
// if it is not in the input
// The user input model has well-defined categories of memory,
// each of which has a specific size. How we use these limits
// depends on the platform we are running on.
input_mem_size(stack, heap, global, overify, ohardfail);
// Initialize local memory allocator & global array tools
ga_initialize_ltd(ma_sizeof(mt_dbl,global,mt_byte));
// this must happen after GA and before MA
util_setup_gpu_affinity();
if ( ga_uses_ma() ) {
if (!ma_init(mt_dbl, stack, heap+global)){
errquit('nwchem.F: ma_init failed (ga_uses_ma=T)',911, MA_ERR);
}
} else{
if (!ma_init(mt_dbl,stack,heap)) {
errquit('nwchem.F: ma_init failed (ga_uses_ma=F)',911, MA_ERR);
}
}
// Touch OpenMP here so that any runtime initialization happens up-front.
// This ensures that any printout that the OpenMP runtime generates,
// such as affinity information, appears at the top of the output file.
// Otherwise, it might not appear until e.g. the CCSD module, at which
// point it will pollute the output file in an undesirable way.
// Do not move this in front of GA/MPI/TCGMSG initialization, since the
// OpenMP runtime may inherit affinity information from MPI that is only
// determined during MPI initialization.
// Format definition is outside of preprocessor protection to ensure the
// label is not accidentally reused, since that will not be caught by
// testing that does not enable OpenMP.
g99 format(2x, 'NWChem w/ OpenMP: Maximum threads = ',i4);
#if defined(USE_OPENMP){
#pragma omp parallel
#pragma omp master
{
if (ga_nodeid() == 0){
write(luout,g99);
omp_get_max_threads();
}
}
#endif
// set no. threads for threaded BLAS to 1
util_blas_set_num_threads(1);
rtdb_init()
// More for amusement then efficiency force all MA allocated entities
// to be aligned at the beginning of a 128 byte cache line
// if (!ma_set_numalign(7)){
// errquit('nwchem.cpp: ma_set_numalign failed',911, MA_ERR);
// }
// aligned to 64byte record
if (!ma_set_numalign(6)){
errquit('nwchem.cpp: ma_set_numalign failed', 911, MA_ERR);
}
//old:------------------------------------------------------- START ---------
//old:C GA allocations come out of MA space, so lump them together
//old:C and let MA impose the limits on GA sizes instead of actually
//old:C using the global limit.
//old:C
//old: if ( ga_uses_ma() ) then
//old: if (.not. ma_init(mt_dbl, stack, heap+global))
//old: $ call errquit('nwchem: ma_init failed', -1)
//old: call ga_initialize
//old:C
//old:C GA allocations are separate from MA, so the separate limit
//old:C must be enforced. Note GA only understands bytes.
//old:C
//old: else
//old: if (.not. ma_init(mt_dbl, stack, heap))
//old: $ call errquit('nwchem: ma_init failed', -1)
//old: call ga_initialize_ltd(ma_sizeof(mt_dbl, global, mt_byte) )
//old: endif
//old:------------------------------------------------------- END -----------
//*** call nxtval_ga_initialize()
// Trap SIGFPE after GA to override handler
//*** call ieeetrap()
#if defined(LINUXALPHA)
dec_fpe(); // To avoid underflow problems on Alpha in Texas
#endif
#ifdef CRAY_T3D
// This as a temporary fix for SIGFPE in Texas that does not seem
// to affect the final results
oldact = fsigctl('IGNORE','SIGFPE',0);
#endif
#ifdef LINUX
// uncommenting this line turns on sigfpe trapping under linux
// linux_trapfpe();
#endif
#ifdef MACX
// uncommenting this line turns on sigfpe trapping under Mac OSX
// macx_trapfpe();
#endif
// Hard fail is good for development but means that we cannot
// respond to allocation problems. Disable by default.
status = ma_set_auto_verify(overify);
status = ma_set_hard_fail(ohardfail);
status = ma_set_error_print(ohardfail);
// Initialize pstat
if (!pstat_init(20,1,' ')){
errquit('nwchem: pstat_init failed', 0, UNKNOWN_ERR);
}
input_file_info(input_filename, rtdb_name, ostartup, ocontinue);
// Now are ready to summarize the environment
nwchem_banner(input_filename, rtdb_name, ostartup, ocontinue);
// Actually open the database and store the file prefix
// Note that only process 0 has the database name ... that is OK.
if (ostartup){
if (!rtdb_open(rtdb_name, 'empty', rtdb)){
errquit('start: rtdb_open empty failed', 0, RTDB_ERR);
}
} else{
if (!rtdb_open(rtdb_name, 'old', rtdb)){
errquit('start: rtdb_open old failed', 0, RTDB_ERR);
}
}
// initialize nxtask
nxtask_init(rtdb);
//!! BGJ
bgj_rtdb = rtdb;
//!! BGJ
if (ostartup || ocontinue){
orestart = false;
} else{
orestart = true;
}
util_set_rtdb_state(rtdb, ostartup, ocontinue, orestart);
util_file_info_rtdb(rtdb); // Save file info for restart
movecs_ecce_print_on();
geom_hnd_parallel(true)
perfm_start();
#ifdef USE_OFFLOAD
util_getppn(ppnout);
if (ppnout == 0){
errquit('util_getppn failed',0,UERR);
}
if (ga_nodeid() == 0){
write(luout,*) ga_nodeid(), ' ppn ', ppnout;
}
if (offload_enabled()){
if (ga_nodeid() < ppnout){
write(luout, '(I8,A,I2)') ga_nodeid(), ' offload enabled, GPU: ',
offload_device();
}
}
ga_sync()
#endif
if (orestart || ocontinue){
nw_print_restart_info(rtdb);
}
// if continue then go right to task stored on rtdb do not further parse
// input. if input is required then user should have used restart
if (ocontinue){
task(rtdb);
}
// Parse input data, shove into database and execute tasks
g10 if (input_parse(rtdb)){ // while(tasks to do)
util_print_rtdb_load(rtdb, ' '); // High level print
if (util_print('tcgmsg', print_never)){
setdbg(1);
} else{
setdbg(0);
}
#ifdef CATAMOUNT
util_allocga();
#endif
task(rtdb);
goto g10; // end while
}
// Close the RTDB
util_print_rtdb_load(rtdb, ' '); // High level print
if (util_print('rtdbvalues', print_debug)){
if (!rtdb_print(rtdb,true)){
errquit('control: rtdb_print failed', 0, RTDB_ERR);
}
} else if (util_print('rtdb', print_high)){
if (! rtdb_print(rtdb, false)){
errquit('control: rtdb_print failed', 0, RTDB_ERR);
}
}
if (!rtdb_close(rtdb, 'keep')){
errquit('nwchem: rtdb_close failed', rtdb, RTDB_ERR);
}
if (util_print('rtdb', print_high) || util_print('rtdbvalues', print_high)){
rtdb_print_usage(); // Called after closing so memory leaks apparent
}
// Tidy up pstat
if (!pstat_terminate()){
errquit('nwchem: pstat_terminate failed', 0, UNKNOWN_ERR);
}
//** nxtval_ga_terminate()
// Print memory and other info
ga_sync();
if (ga_nodeid == 0){
if (util_print('ga summary', print_default)){
ga_summarize(0);
}
if (util_print('ga stats', print_default)){
ga_print_stats();
write(LuOut,*);
}
}
return 0;
}

105
src/rtdb/rtdb.h Normal file
View file

@ -0,0 +1,105 @@
//
// 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]
// <ma_type>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]
// <ma_type>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;

2273
src/tce/oce.py Normal file

File diff suppressed because it is too large Load diff

32
src/tce/splitfiles.py Normal file
View file

@ -0,0 +1,32 @@
#!/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")
nfiles = 0
for line in source:
if (string.find(line,"SUBROUTINE") != -1):
if (nfiles):
file = open(filename+".F","w")
for newline in filecontent:
file.write(newline)
filename = string.split(line[string.find(line,"SUBROUTINE")+11:],"(")[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")
for newline in filecontent:
file.write(newline)
print("Number of files generated:",nfiles)

33
src/util/errquit.h Normal file
View file

@ -0,0 +1,33 @@
// UERR - Not yet assigned to a category
// UNKNOWN_ERR - Not yet assigned to a category
// MEM_ERROR - 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
// BASIS_ERR - Error related to basis set
// GEOM_ERR - Error related to geometry
// MA_ERR - local memory error
// GA_ERR - global memory error
// INT_ERR - error related to integrals
// DISK_ERR - error in reading or writing from disk
// CALC_ERR - calculation failed to converge
// FMM_ERR -
// STACK_ERR - error in MA stack
// HEAP_ERR - error in MA heap
const int UERR = 0;
const int UNKNOWN_ERR = 0;
const int MEM_ERR = 10;
const int STACK_ERR = 11;
const int HEAP_ERR = 12;
const int RTDB_ERR = 20;
const int INPUT_ERR = 30;
const int CAPMIS_ERR = 40;
const int BASIS_ERR = 50;
const int GEOM_ERR = 60;
const int GA_ERR = 70;
const int MA_ERR = 80;
const int INT_ERR = 90;
const int DISK_ERR = 100;
const int CALC_ERR = 110;
const int FMM_ERR = 120;
// $Id$