Codebase list votca-xtp / 1b2bccf1-4511-4a27-bd7b-f49ebfd9899c/main scripts / xtp_qmmm2qm.in
1b2bccf1-4511-4a27-bd7b-f49ebfd9899c/main

Tree @1b2bccf1-4511-4a27-bd7b-f49ebfd9899c/main (Download .tar.gz)

xtp_qmmm2qm.in @1b2bccf1-4511-4a27-bd7b-f49ebfd9899c/mainraw · history · blame

#! /usr/bin/env python3
#
# Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
#
# Licensed under the Apache 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
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
#

import h5py
import sys
import os
import argparse
import importlib

VERSION = '@PROJECT_VERSION@ #CSG_GIT_ID#'
PROGTITLE = 'THE VOTCA::XTP QMMM orbfile converter'
PROGDESCR = 'Convert QMMM orb file into a DFTGWBSE-like orb file usable by gencube,densityanalysis,...'
VOTCAHEADER = '''\
==================================================
========   VOTCA (http://www.votca.org)   ========
==================================================
{progtitle}
please submit bugs to @PROJECT_CONTACT@
xtp_qmmm2qm, version {version}
'''.format(version=VERSION, progtitle=PROGTITLE)


parser = argparse.ArgumentParser(prog='xtp_qmmm2qm')

parser.add_argument("-f", "--file", help="Input File (String)")
parser.add_argument("-r", "--region", help="QMMM region number (Index)")
parser.add_argument('-v', '--verbosity', action="count", help="Verbose mode")
args = parser.parse_args()


region = "region_" + args.region
file_name, ext = os.path.splitext(args.file)


print (VOTCAHEADER)
print("...Input file: ", args.file)

print("...Selected region: ", region)

with h5py.File(args.file, 'r') as data_qmmm:
    #Check if selected region exists in the database
    if region in data_qmmm.keys():
        # Create database similar to the simple QM one
        new_file_name = file_name + "_QMlike" + ext
        with h5py.File(new_file_name,'w') as dataset:
            data_qmmm.copy(region+'/orbitals', dataset)
            dataset.move('orbitals','QMdata')
            if args.verbosity:
                print("...Checking keys")
                print(list(dataset["QMdata"].keys()))
        print("...Congrats! Your new file is ready with name: ", new_file_name)
    else:
        print("ERROR: The selcted region doesn't exist")
        print("Available regions: ", list(data_qmmm.keys()))