org.jmol.adapter.readers.quantum.GenNBOReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmol Show documentation
Show all versions of jmol Show documentation
Jmol: an open-source Java viewer for chemical structures in 3D
/* $RCSfile$
* $Author: hansonr $
* $Date: 2006-09-12 00:46:22 -0500 (Tue, 12 Sep 2006) $
* $Revision: 5501 $
*
* Copyright (C) 2004-2005 The Jmol Development Team
*
* Contact: [email protected]
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jmol.adapter.readers.quantum;
import java.io.BufferedReader;
import java.util.Hashtable;
import java.util.Map;
import javajs.util.AU;
import javajs.util.Lst;
import javajs.util.PT;
import javajs.util.Rdr;
import javajs.util.SB;
import org.jmol.adapter.smarter.Atom;
import org.jmol.quantum.QS;
import org.jmol.util.Logger;
/**
* NBO file nn reader will pull in other files as necessary
*
* acknowledgments: Grange Hermitage, Frank Weinhold
*
*
* upgrade to NBO 6 allows reading of resonance structures, including base structure
*
*
* @author hansonr
**/
public class GenNBOReader extends MOReader {
//
// *********************************** NBO 6.0 ***********************************
// N A T U R A L A T O M I C O R B I T A L A N D
// N A T U R A L B O N D O R B I T A L A N A L Y S I S
// **************************** Robert Hanson (100634) ***************************
// (c) Copyright 1996-2014 Board of Regents of the University of Wisconsin System
// on behalf of the Theoretical Chemistry Institute. All rights reserved.
//
// Cite this program as:
//
// NBO 6.0. E. D. Glendening, J. K. Badenhoop, A. E. Reed,
// J. E. Carpenter, J. A. Bohmann, C. M. Morales, C. R. Landis,
// and F. Weinhold (Theoretical Chemistry Institute, University
// of Wisconsin, Madison, WI, 2013); http://nbo6.chem.wisc.edu/
//
// /NLMO / : Form natural localized molecular orbitals
// /NRT / : Natural Resonance Theory Analysis
// /AOPNAO / : Print the AO to PNAO transformation
// /SAO / : Print the AO overlap matrix
// /STERIC / : Print NBO/NLMO steric analysis
// /CMO / : Print analysis of canonical MOs
// /PLOT / : Write information for the orbital plotter
// /FILE / : Set to co2_p
//
// Filename set to co2_p
private boolean isOutputFile;
private String nboType = "";
private int nOrbitals0;
private boolean is47File;
private boolean isOpenShell;
private boolean alphaOnly, betaOnly;
private int nAOs;
@Override
protected void initializeReader() throws Exception {
/*
* molname.31 AO
* molname.32 PNAO
* molname.33 NAO
* molname.34 PNHO
* molname.35 NHO
* molname.36 PNBO
* molname.37 NBO
* molname.38 PNLMO
* molname.39 NLMO
* molname.40 MO
* molname.41 AO density matrix
* molname.46 Basis label file
* molname.47 archive file
* molname.nbo output file
*
*/
String line1 = rd().trim();
is47File = (line1.indexOf("$GENNBO") >= 0 || line1.indexOf("$NBO") >= 0); // GENNBO 6
alphaOnly = is47File || checkFilterKey("ALPHA");
betaOnly = !is47File && checkFilterKey("BETA");
if (is47File) {
readData47();
return;
}
boolean isOK;
String line2 = rd();
line = line1 + line2;
isOutputFile = (line2.indexOf("****") >= 0);
if (isOutputFile) {
// this may or may not work.
isOK = getFile31();
super.initializeReader();
// keep going -- we need to read the file using MOReader
moData.put("isNormalized", Boolean.TRUE);
} else if (line2.indexOf("s in the AO basis:") >= 0) {
nboType = line2.substring(1, line2.indexOf("s"));
asc.setCollectionName(line1 + ": " + nboType + "s");
isOK = getFile31();
} else {//if (line.indexOf("Basis set information") >= 0) {
nboType = "AO";
asc.setCollectionName(line1 + ": " + nboType + "s");
isOK = readData31(line1);
}
if (!isOK)
Logger.error("Unimplemented shell type -- no orbitals available: " + line);
if (isOutputFile)
return;
if (isOK)
readMOs();
continuing = false;
}
// $GENNBO NATOMS=7 NBAS=28 UPPER BODM FORMAT $END
// $NBO $END
// $COORD
// Methylamine...RHF/3-21G//Pople-Gordon geometry
// 6 6 0.745914 0.011106 0.000000
// 7 7 -0.721743 -0.071848 0.000000
// 1 1 1.042059 1.060105 0.000000
// 1 1 1.129298 -0.483355 0.892539
// 1 1 1.129298 -0.483355 -0.892539
// 1 1 -1.076988 0.386322 -0.827032
// 1 1 -1.076988 0.386322 0.827032
// $END
@Override
protected void finalizeSubclassReader() throws Exception {
appendLoadNote("NBO type " + nboType);
if (isOpenShell)
asc.setCurrentModelInfo("isOpenShell", Boolean.TRUE);
finalizeReaderASCR();
}
private void readMOs() throws Exception {
nOrbitals0 = orbitals.size();
// get the labels
getFile46();
if (betaOnly) {
discardLinesUntilContains("BETA");
filterMO();
}
boolean isAO = nboType.equals("AO");
boolean isNBO = !isAO && !nboType.equals("MO");
nOrbitals = orbitals.size();
if (nOrbitals == 0)
return;
line = null;
if (!isNBO)
nOrbitals = nOrbitals0 + nAOs;
for (int i = nOrbitals0; i < nOrbitals; i++) {
Map mo = orbitals.get(i);
float[] coefs = new float[nAOs];
mo.put("coefficients", coefs);
if (!isAO) {
if (line == null) {
while (rd() != null && Float.isNaN(parseFloatStr(line))) {
filterMO(); //switch a/b
}
} else {
line = null;
}
fillFloatArray(line, 0, coefs);
if (Float.isNaN(coefs[0]))
System.out.println("testing gennboreader");
line = null;
//setMOType(mo, i);
} else {
coefs[i] = 1;
}
}
if (nboType.equals("NBO")) {
float[] occupancies = new float[nOrbitals - nOrbitals0];
fillFloatArray(null, 0, occupancies);
for (int i = nOrbitals0; i < nOrbitals; i++) {
Map mo = orbitals.get(i);
mo.put("occupancy", Float.valueOf(occupancies[i - nOrbitals0]));
}
}
moData.put(nboType + "_coefs", orbitals);
setMOData(false);
moData.put("isNormalized", Boolean.TRUE);
moData.put("nboType", nboType);
Logger.info((orbitals.size() - nOrbitals0) + " orbitals read");
}
private String topoType = "A";
@Override
protected boolean checkLine() throws Exception {
// for .nbo only
if (line.indexOf("SECOND ORDER PERTURBATION THEORY ANALYSIS") >= 0
&& !orbitalsRead) {
// Frank Weinhold suggests that NBO/.37 is not the best choice for a default.
// PNBOs (pre-NBOs) are not orthogonalized and so "look better." But we are already
// reading NBOs, and they are fine as well. I'd rather not change this
// default and risk changes in PNGJ files already saved.
nboType = "NBO";
String data = getFileData(".37");
if (data == null)
return true;
BufferedReader readerSave = reader;
reader = Rdr.getBR(data);
rd();
rd();
readMOs();
reader = readerSave;
orbitalsRead = false;
return true;
}
if (line.indexOf("$NRTSTRA") >= 0) {
getStructures("NRTSTRA");
return true;
}
if (line.indexOf("$NRTSTRB") >= 0) {
getStructures("NRTSTRB");
return true;
}
if (line.indexOf("$NRTSTR") >= 0) {
getStructures("NRTSTR");
return true;
}
if (line.indexOf(" TOPO ") >= 0) {
getStructures("TOPO" + topoType);
topoType = "B";
return true;
}
if (line.indexOf("$CHOOSE") >= 0) {
getStructures("CHOOSE");
return true;
}
return checkNboLine();
}
private int nStructures = 0;
NBOParser nboParser;
private void getStructures(String type) throws Exception {
if (nboParser == null)
nboParser = new NBOParser();
Lst