def test_cube(self): """Does the cube file written out for electron density on a Cartesian grid match expected values? """ data, logfile = getdatafile(Psi4, "basicPsi4-1.2.1", ["water_mp2.out"]) # Reference values were calculated using cubegen method in Psi4. # First six rows are information about the coordinates of the grid and comments. tmp = [] with open(os.path.dirname(os.path.realpath(__file__)) + "/water_mp2.cube") as f: lines = f.readlines() for line in lines[6 : len(lines)]: tmp.extend(line.split()) tmp = numpy.asanyarray(tmp, dtype=float) refcube = numpy.resize(tmp, (13, 13, 13)) # Values for the grid below are constructed to match Psi4 cube file. vol = volume.Volume( (-1.587532, -1.587532, -1.356299), (1.58754, 1.58754, 1.81877), (0.26458860545, 0.26458860545, 0.26458860545), ) density = volume.electrondensity(data, vol, [data.mocoeffs[0][: data.homos[0]]]) assert_allclose(density.data, refcube, atol=0.5, rtol=0.1)
def test_roundtrip_cube(self): """Write a cube file and then read it back. Check if the volume object contains identical information on each grid point""" data, logfile = getdatafile(Psi4, "basicPsi4-1.2.1", ["water_mp2.out"]) vol = volume.Volume((-1, -1, -1), (1, 1, 1), (0.4, 0.4, 0.4)) density = volume.electrondensity(data, vol, [data.mocoeffs[0][: data.homos[0]]]) density.writeascube("coarsewater.cube") density_recovered = volume.read_from_cube("coarsewater.cube") assert_allclose(density.data, density_recovered.data, rtol=0.05)
def test_density(self): """Does the volume occupied by the combined electron density integrate to the correct value? """ data_basis, _ = getdatafile(Gaussian, "basicGaussian09", ["dvb_sp.out"]) data_sp, _ = getdatafile(Gaussian, "basicGaussian09", ["dvb_sp.out"]) vol = volume.Volume((-3.0, -6.0, -2.0), (3.0, 6.0, 2.0), (0.25, 0.25, 0.25)) frontierorbs = [data_sp.mocoeffs[0][(data_sp.homos[0] - 3) : (data_sp.homos[0] + 1)]] density = volume.electrondensity(data_sp, vol, frontierorbs) integral = density.integrate() self.assertTrue(abs(integral - 8.00) < 1e-2) print("Combined Density of 4 Frontier orbitals=", integral)
def test_density(self): """Does the volume occupied by the combined electron density integrate to the correct value? """ data_basis, _ = getdatafile(Gaussian, "basicGaussian03", ["dvb_sp_basis.log"]) data_sp, _ = getdatafile(Gaussian, "basicGaussian03", ["dvb_sp.out"]) vol = volume.Volume((-3.0, -6.0, -2.0), (3.0, 6.0, 2.0), (0.25, 0.25, 0.25)) frontierorbs = [data_sp.mocoeffs[0][(data_sp.homos[0] - 3):(data_sp.homos[0] + 1)]] density = volume.electrondensity(data_sp.atomcoords[0], frontierorbs, data_basis.gbasis, vol) integral = density.integrate() self.assertTrue(abs(integral - 8.00) < 1e-2) print("Combined Density of 4 Frontier orbitals=", integral)
def main(): args = _parse_args() log_file = ccopen(args.quantum_chemical_file) data = log_file.parse() me = MolecularExtent(data, args.radius) me.calculate_extent(args.index) volume = Volume(me.lower_limit, me.upper_limit, spacing=(args.spacing, args.spacing, args.spacing)) slice_end = data.homos[args.spinidx] + 1 print('density of molecular orbitals [0..%d] H**O=%d' % (slice_end, data.homos[args.spinidx])) density = electrondensity(data.atomcoords[args.index], data.mocoeffs[args.spinidx][0:slice_end], data.gbasis, volume) print('integral', density.integrate(), density.integrate_square()) if args.output is not None: density.writeascube(args.output + '.cube')