1#!/usr/bin/env python 2# Copyright 2014-2020 The PySCF Developers. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import sys 17import numpy 18from pyscf.scf import chkfile 19from pyscf.scf import hf 20 21def mulliken(filename, key='scf'): 22 '''Reading scf/mcscf information from chkfile, then do Mulliken population 23 analysis for the density matrix 24 ''' 25 if key.lower() == 'mcscf': 26 mol = chkfile.load_mol(filename) 27 mo_coeff = chkfile.load(filename, 'mcscf/mo_coeff') 28 mo_occ = chkfile.load(filename, 'mcscf/mo_occ') 29 else: 30 mol, mf = chkfile.load_scf(filename) 31 mo_coeff = mf['mo_coeff'] 32 mo_occ = mf['mo_occ'] 33 dm = numpy.dot(mo_coeff*mo_occ, mo_coeff.T) 34 hf.mulliken_meta(mol, dm) 35 36def dump_mo(filename, key='scf'): 37 '''Read scf/mcscf information from chkfile, then dump the orbital 38 coefficients. 39 ''' 40 from pyscf.tools import dump_mat 41 if key.lower() == 'mcscf': 42 mol = chkfile.load_mol(filename) 43 mo_coeff = chkfile.load(filename, 'mcscf/mo_coeff') 44 else: 45 mol, mf = chkfile.load_scf(filename) 46 mo_coeff = mf['mo_coeff'] 47 dump_mat.dump_mo(mol, mo_coeff) 48 49def molden(filename, key='scf'): 50 '''Read scf/mcscf information from chkfile, then convert the scf/mcscf 51 orbitals to molden format. 52 ''' 53 from pyscf.tools import molden 54 molden.from_chkfile(filename+'.molden', filename, key+'/mo_coeff') 55 56if __name__ == '__main__': 57 if len(sys.argv) == 1: 58 print('%s chkfile_name [pop|mo|molden] [scf|mcscf]' % sys.argv[0]) 59 exit() 60 filename = sys.argv[1] 61 fndic = {'pop': mulliken, 62 'mo': dump_mo, 63 'molden': molden} 64 fn = fndic[sys.argv[2].lower()] 65 if len(sys.argv) > 3: 66 key = sys.argv[3] 67 fn(filename, key) 68 else: 69 fn(filename) 70