def test_Plotting(self): g = Graphics3D(image_size=[1500, 1500], plot_range=[[-10, 10]] * 3, backend="VTK") h5 = Molecule.from_file( self.test_log_h2, # self.test_fchk, # bonds = [ # [0, 1, 1], # [0, 2, 1] # ] ) h5.plot( figure=g # mode='3D', # bond_style= { "circle_points": 24 }, # atom_style= { "sphere_points": 24 } ) m = Molecule.from_file(self.test_fchk, bonds=[[0, 1, 1], [0, 2, 1]]) m.plot( figure=g # mode='3D', # bond_style= { "circle_points": 24 }, # atom_style= { "sphere_points": 24 } )
def test_RenormalizeGaussianModes(self): with GaussianFChkReader(self.test_HOD) as gr: parse = gr.parse([ "Coordinates", "Gradient", "AtomicMasses", "ForceConstants", "ForceDerivatives", "VibrationalModes", "VibrationalData" ]) coords = UnitsData.convert("Angstroms", "AtomicUnitOfLength") * parse["Coordinates"] masses = UnitsData.convert("AtomicMassUnits", "AtomicUnitOfMass") * parse["AtomicMasses"] modes = parse["VibrationalModes"].T freqs = parse["VibrationalData"]["Frequencies"] fcs = parse["ForceConstants"].array sad = UnitsData.convert("Hartrees", "Wavenumbers") * np.sqrt( np.diag(np.dot(np.dot(modes.T, fcs), modes))) modes = modes * freqs / sad print( UnitsData.convert("Hartrees", "Wavenumbers") * np.sqrt(np.diag(np.dot(np.dot(modes.T, fcs), modes)))) masses = np.broadcast_to(masses, (len(masses), 3)).T.flatten() # print(modes-np.linalg.pinv(modes).T) print(np.dot(np.dot(modes.T, np.diag(masses)), modes)) modes_2 = Molecule.from_file( self.test_HOD).get_normal_modes(normalize=False) mm = modes_2._basis.matrix print(np.dot(np.dot(mm.T, np.diag(masses)), mm)) print( UnitsData.convert("Hartrees", "Wavenumbers") * np.sqrt(np.diag(np.dot(np.dot(mm.T, fcs), mm))))
def test_HODModes(self): # oops f****d up getting D out m = Molecule.from_file(self.test_HOD, bonds=[[0, 1, 1], [0, 2, 1]]) modes = m.normal_modes self.assertEquals(m.atoms, ("O", "H", "D")) self.assertEquals(tuple(np.round(modes.freqs)), (1422.0, 2810.0, 3874.0))
def test_VisualizeNormalModes(self): from Psience.Molecools.Vibrations import VibrationalModes, NormalModeCoordinates from McUtils.Plots import GraphicsGrid, Graphics3D m = Molecule.from_file(self.test_fchk, bonds=[[0, 1, 1], [0, 2, 1]]) with GaussianFChkReader(self.test_fchk) as reader: parse = reader.parse(("VibrationalModes", "VibrationalData")) modes = parse["VibrationalModes"].T test_freqs = parse["VibrationalData"]["Frequencies"] nms = m.normal_modes realvibs = VibrationalModes(m, basis=NormalModeCoordinates( modes, freqs=test_freqs)) plot_vibrations = False if plot_vibrations: nmodes = 1 mode_start = 0 g = GraphicsGrid(nrows=2, ncols=nmodes, graphics_class=Graphics3D, plot_range=[[-2, 2], [-2, 2], [-2, 2]], fig_kw=dict(figsize=(17, 5)), tighten=True) for i in range(nmodes): nms.visualize(step_size=.1, figure=g[0, i], which=mode_start + i, anim_opts=dict(interval=10)) for i in range(nmodes): realvibs.visualize(step_size=.1, figure=g[1, i], which=mode_start + i, anim_opts=dict(interval=10)) g.show() self.assertEquals(tuple(round(a, 4) for a in nms.freqs), tuple(round(a, 4) for a in test_freqs))
def test_H2OModes(self): m = Molecule.from_file(self.test_fchk, bonds=[[0, 1, 1], [0, 2, 1]]) modes = m.normal_modes self.assertEquals(m.atoms, ("O", "H", "H")) self.assertEquals(tuple(np.round(modes.freqs)), (1622.0, 3803.0, 3938.0))
def test_AutoZMat(self): m = Molecule.from_file(self.test_fchk)
def test_Frags(self): m = Molecule.from_file(self.test_fchk) self.assertEquals(len(m.prop("fragments")), 1)
def test_BondGuessing(self): m = Molecule.from_file(self.test_fchk) self.assertEquals(m.bonds, [[0, 1, 1], [0, 2, 1]])
def test_ImportMolecule(self): n = 3 # water m = Molecule.from_file(self.test_fchk) self.assertEquals(m.atoms, ("O", "H", "H"))