org.jmol.adapter.readers.quantum.SlaterReader 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: egonw $
* $Date: 2006-03-18 15:59:33 -0600 (Sat, 18 Mar 2006) $
* $Revision: 4652 $
*
* Copyright (C) 2003-2005 Miguel, Jmol Development, www.jmol.org
*
* 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 org.jmol.quantum.SlaterData;
import org.jmol.util.Logger;
import javajs.util.Lst;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
/**
*
* @author hansonr
*/
abstract class SlaterReader extends BasisFunctionReader {
/*
* -- this abstract superclass is cartesian bases only (s, p, d, f)
*
* -- MopacReader overrides this for spherical bases (s, p, d)
*
*/
protected final Lst slaters = new Lst();
protected SlaterData[] slaterArray;
/**
*
* We build two data structures for each slater:
*
* int[] slaterInfo[] = {iatom, a, b, c, d}
* float[] slaterData[] = {zeta, coef}
*
* where
*
* psi = (coef)(x^a)(y^b)(z^c)(r^d)exp(-zeta*r)
*
* Mopac: a == -2 ==> z^2 ==> (coef)(2z^2-x^2-y^2)(r^d)exp(-zeta*r)
* and: b == -2 ==> (coef)(x^2-y^2)(r^d)exp(-zeta*r)
*
* @param iAtom
* @param a
* @param b
* @param c
* @param d
* @param zeta
* @param coef
*/
protected final void addSlater(int iAtom, int a, int b, int c, int d,
double zeta, float coef) {
//System.out.println ("SlaterReader " + slaters.size() + ": " + iAtom + " " + a + " " + b + " " + c + " " + d + " " + zeta + " " + coef);
slaters.addLast(new SlaterData(iAtom, a, b, c, d, zeta, coef));
}
protected void addSlater(SlaterData sd, int n) {
sd.index = n;
slaters.addLast(sd);
}
/**
* after the vectors intinfo and floatinfo are completed, we
*
* @param doScale
* @param doSort TODO
*/
protected final void setSlaters(boolean doScale, boolean doSort) {
if (slaterArray == null) {
int nSlaters = slaters.size();
slaterArray = new SlaterData[nSlaters];
for (int i = 0; i < slaterArray.length; i++)
slaterArray[i] = slaters.get(i);
}
if (doScale)
for (int i = 0; i < slaterArray.length; i++) {
SlaterData sd = slaterArray[i];
sd.coef *= scaleSlater(sd.x, sd.y, sd.z, sd.r, sd.zeta);
if (debugging) {
Logger.debug("SlaterReader " + i + ": " + sd.iAtom + " " + sd.x + " " + sd.y + " " + sd.z + " " + sd.r + " " + sd.zeta + " " + sd.coef);
}
}
if (doSort) {
Arrays.sort(slaterArray, new SlaterSorter());
int[] pointers = new int[slaterArray.length];
for (int i = 0; i < slaterArray.length; i++)
pointers[i] = slaterArray[i].index;
sortOrbitalCoefficients(pointers);
}
moData.put("slaters", slaterArray);
asc.setCurrentModelInfo("moData", moData);
}
class SlaterSorter implements Comparator {
@Override
public int compare(SlaterData sd1, SlaterData sd2) {
return ( sd1.iAtom < sd2.iAtom ? -1 : sd1.iAtom > sd2.iAtom ? 1 : 0);
}
}
protected final void setMOs(String units) {
moData.put("mos", orbitals);
moData.put("energyUnits", units);
finalizeMOData(moData);
}
/**
* sorts coefficients by atomic number for speed later
*
* @param pointers
*/
protected void sortOrbitalCoefficients(int[] pointers) {
// now sort the coefficients as well
for (int i = orbitals.size(); --i >= 0; ) {
Map mo = orbitals.get(i);
float[] coefs = (float[]) mo.get("coefficients");
float[] sorted = new float[pointers.length];
for (int j = 0; j < pointers.length; j++) {
int k = pointers[j];
if (k < coefs.length)
sorted[j] = coefs[k];
}
mo.put("coefficients", sorted);
}
}
/**
*
* sorts orbitals by energy rather than by symmetry
* so that we can use "MO HOMO" "MO HOMO - 1" "MO LUMO"
*
*/
@SuppressWarnings("unchecked")
protected void sortOrbitals() {
Map[] array = orbitals.toArray(new Map[0]);
Arrays.sort(array, new OrbitalSorter());
orbitals.clear();
for (int i = 0; i < array.length; i++)
orbitals.addLast(array[i]);
}
class OrbitalSorter implements Comparator