Codebase list votca-xtp / upstream/1.5 scripts / xtp_update_exciton.in
upstream/1.5

Tree @upstream/1.5 (Download .tar.gz)

xtp_update_exciton.in @upstream/1.5raw · history · blame

#! /usr/bin/env python
#
# Copyright 2009-2018 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.
#

from __future__ import print_function
VERSION='@PROJECT_VERSION@ #CSG_GIT_ID#'
import sys
import os
import time
import argparse
import sqlite3

PROGTITLE = 'THE VOTCA::XTP STATE-FILE UPDATER FOR EXCITON EXTENSION'
PROGDESCR = 'Updates the CTP state file to additionally use singlets and triplets +'
VOTCAHEADER = '''\
==================================================
========   VOTCA (http://www.votca.org)   ========
==================================================

{progtitle}

please submit bugs to bugs@votca.org 
xtp_update_exciton, version {version}

'''.format(version=VERSION, progtitle=PROGTITLE)

def okquit(what=''):
	if what != '': print (what)
	sys.exit(0)
# =============================================================================
# PROGRAM OPTIONS
# =============================================================================

class XtpHelpFormatter(argparse.HelpFormatter):
	def _format_usage(self, usage, action, group, prefix):
		return VOTCAHEADER
		
progargs = argparse.ArgumentParser(prog='xtp_update_exciton',
    formatter_class=lambda prog: XtpHelpFormatter(prog,max_help_position=70),
	description=PROGDESCR)
	
progargs.add_argument('-f', '--file',
    dest='sqlfile',   
    action='store',
    required=True,
    type=argparse.FileType('w'),
	default='',
    help='State file to update.')
    
OPTIONS = progargs.parse_args()


# =============================================================================
# SQLITE3 EXECUTION
# =============================================================================

conn = sqlite3.connect(OPTIONS.sqlfile)
port = conn.cursor()

try:
	port.execute('ALTER TABLE segments ADD COLUMN UnXnNs REAL;')
	port.execute('ALTER TABLE segments ADD COLUMN UnXnNt REAL;')
	port.execute('ALTER TABLE segments ADD COLUMN UxNxXs REAL;')
	port.execute('ALTER TABLE segments ADD COLUMN UxNxXt REAL;')
	port.execute('ALTER TABLE segments ADD COLUMN UxXnNs REAL;')
	port.execute('ALTER TABLE segments ADD COLUMN UxXnNt REAL;')
	port.execute('ALTER TABLE segments ADD COLUMN eSinglet REAL;')
	port.execute('ALTER TABLE segments ADD COLUMN eTriplet REAL;')
	port.execute('ALTER TABLE segments ADD COLUMN has_s REAL;')
	port.execute('ALTER TABLE segments ADD COLUMN has_t REAL;')
	port.execute('ALTER TABLE segments ADD COLUMN occPs REAL;')
	port.execute('ALTER TABLE segments ADD COLUMN occPt REAL;')
	port.execute('UPDATE segments SET UnXnNs=0,UnXnNt=0,UxNxXs=0,UxNxXt=0,UxXnNs=0,UxXnNt=0,eSinglet=0,eTriplet=0,has_s=0,has_t=0,occPs=-1,occPt=-1;')




except:
	print ("'segments' table already up-to-date")
	
try:
	port.execute('ALTER TABLE pairs ADD COLUMN lOs REAL;')
	port.execute('ALTER TABLE pairs ADD COLUMN lOt REAL;')
	port.execute('ALTER TABLE pairs ADD COLUMN has_s REAL;')
	port.execute('ALTER TABLE pairs ADD COLUMN has_t REAL;')
	port.execute('ALTER TABLE pairs ADD COLUMN rate12s REAL;')
	port.execute('ALTER TABLE pairs ADD COLUMN rate21s REAL;')
	port.execute('ALTER TABLE pairs ADD COLUMN rate12t REAL;')
	port.execute('ALTER TABLE pairs ADD COLUMN rate21t REAL;')
	port.execute('ALTER TABLE pairs ADD COLUMN Jeff2s REAL;')
	port.execute('ALTER TABLE pairs ADD COLUMN Jeff2t REAL;')
	port.execute('UPDATE pairs SET IOs=0,IOt=0,rate12s=0,rate12t=0,rate21s=0,rate21t=0,Jeff2s=0,Jeff2t=0,has_s=0,has_t=0;')
except:
	print ("'pairs' table already up-to-date")

conn.commit()
conn.close()
sys.exit(0)