示例#1
0
    def compute_normal_modes(self, write_jmol=True):
        """
        Use ase calculator to compute numerical frequencies for the molecule
        Args:
            write_jmol (bool): Write frequencies to input file for visualization in jmol (default=True)
        """
        freq_file = os.path.join(self.working_dir, "normal_modes")

        # Compute frequencies
        frequencies = Vibrations(self.molecule, name=freq_file)
        frequencies.run()

        # Print a summary
        frequencies.summary()

        # Write jmol file if requested
        if write_jmol:
            frequencies.write_jmol()
示例#2
0
def freq(atoms=None):
    if atoms is None:
        atoms = read('md.traj', index=0)
    atoms.calc = IRFF(atoms=atoms,
                      libfile='ffield.json',
                      rcut=None,
                      nn=True,
                      massage=2)
    # Compute frequencies
    frequencies = Vibrations(atoms, name='freq')
    frequencies.run()
    # Print a summary
    frequencies.summary()
    frequencies.write_dos()

    # Write jmol file if requested
    # if write_jmol:
    frequencies.write_jmol()
示例#3
0
	def run_task(self,fw_spec): 
		"""ONLY WORKS FOR QUANTUM ESPRESSO"""

		from ase.vibrations       import Vibrations

		jobID	= fw_spec['jobID']
		job 	= db2object(jobID)
		t0 		= time.time()
		atoms 	= job.atoms()
		
		atoms.set_calculator(job.vibCalc())

		vib = Vibrations(atoms,delta=job.delta(),indicies=job.vibids)

		vib.run()
		vib.summary(log='vibrations.txt')
		vib.write_jmol()

		vibs 	= vib.get_frequencies()
		t 		= (time.time()-t0)/60.0 #min
	
		return FWAction(stored_data= {'vibs':vibs,'avgtime':t},mod_spec=[{'_push': {'vibs':vibs,'time':t}}])
示例#4
0
    def test_vibration_on_surface(self, testdir):
        from ase.build import fcc111, add_adsorbate
        ag_slab = fcc111('Ag', (4, 4, 2), a=2)
        n2 = Atoms('N2',
                   positions=[[0., 0., 0.], [0., np.sqrt(2),
                                             np.sqrt(2)]])
        add_adsorbate(ag_slab, n2, height=1, position='fcc')

        # Add an interaction between the N atoms
        hessian_bottom_corner = np.zeros((2, 3, 2, 3))
        hessian_bottom_corner[-1, :, -2] = [1, 1, 1]
        hessian_bottom_corner[-2, :, -1] = [1, 1, 1]

        hessian = np.zeros((34, 3, 34, 3))
        hessian[32:, :, 32:, :] = hessian_bottom_corner

        ag_slab.calc = ForceConstantCalculator(hessian.reshape(
            (34 * 3, 34 * 3)),
                                               ref=ag_slab.copy(),
                                               f0=np.zeros((34, 3)))

        # Check that Vibrations with restricted indices returns correct Hessian
        vibs = Vibrations(ag_slab, indices=[-2, -1])
        vibs.run()
        vibs.read()

        assert_array_almost_equal(vibs.get_vibrations().get_hessian(),
                                  hessian_bottom_corner)

        # These should blow up if the vectors don't match number of atoms
        vibs.summary()
        vibs.write_jmol()

        for i in range(6):
            # Frozen atoms should have zero displacement
            assert_array_almost_equal(vibs.get_mode(i)[0], [0., 0., 0.])

            # The N atoms should have finite displacement
            assert np.all(vibs.get_mode(i)[-2:, :])
示例#5
0
	def run_task(self,fw_spec): 
		"""ONLY WORKS FOR QUANTUM ESPRESSO"""
		from ase.vibrations       import Vibrations
		job,params,atoms = initialize(fw_spec)
		
		prev = g.glob('*.pckl') #delete incomplete pckls - facilitating restarted jobs
		for p in prev:
			if os.stat(p).st_size < 100: os.remove(p)
		
		atoms.set_calculator(job.vibCalc())
		vib = Vibrations(atoms,delta=job.delta(),indices=job.vibids())


		vib.run(); vib.write_jmol()
		vib.summary(log='vibrations.txt')
		with open('vibrations.txt','r') as f: vibsummary = f.read()

		vib_energies,vib_frequencies = vib.get_energies(),vib.get_frequencies()
		resultDict 	= misc.mergeDicts([params,	{'vibfreqs_pckl': pickle.dumps(vib_frequencies)
												,'vibsummary':vibsummary
												,'vibengs_pckl':pickle.dumps(vib_energies)}])

		with open('result.json', 'w') as outfile: json.dumps(resultDict, outfile)
		return fireworks.core.firework.FWAction(stored_data=resultDict)
示例#6
0
    def test_vibrations_on_surface(self, testdir):
        atoms = self.n2_on_ag.copy()
        atoms.calc = EMT()
        vibs = Vibrations(atoms, indices=[-2, -1])
        vibs.run()

        freqs = vibs.get_frequencies()
        assert len(freqs) == 6

        vib_data = vibs.get_vibrations()
        assert_array_almost_equal(freqs, vib_data.get_frequencies())

        # These should blow up if the vectors don't match number of atoms
        vibs.summary()
        vibs.write_jmol()

        for i in range(6):
            # Frozen atoms should have zero displacement
            assert_array_almost_equal(vibs.get_mode(i)[0], [0., 0., 0.])

            # At least one of the N atoms should have finite displacement
            # (It's a strange test system, the N aren't interacting.)

            assert np.any(vibs.get_mode(i)[-2:, :])
示例#7
0
文件: test_vib.py 项目: YanJordan/ase
    def test_vibrations(self, testdir, n2_emt, n2_optimized):
        atoms = n2_emt
        vib = Vibrations(atoms)
        vib.run()
        freqs = vib.get_frequencies()
        vib.write_mode(n=None, nimages=5)
        vib.write_jmol()
        vib_energies = vib.get_energies()

        for image in vib.iterimages():
            assert len(image) == 2

        thermo = IdealGasThermo(vib_energies=vib_energies,
                                geometry='linear',
                                atoms=atoms,
                                symmetrynumber=2,
                                spin=0)
        thermo.get_gibbs_energy(temperature=298.15,
                                pressure=2 * 101325.,
                                verbose=False)

        vib.summary(log=self.logfile)
        with open(self.logfile, 'rt') as f:
            log_txt = f.read()
            assert log_txt == vibrations_n2_log

        mode1 = vib.get_mode(-1)
        assert_array_almost_equal(mode1,
                                  [[0., 0., -0.188935], [0., 0., 0.188935]])

        assert_array_almost_equal(
            vib.show_as_force(-1, show=False).get_forces(),
            [[0., 0., -2.26722e-1], [0., 0., 2.26722e-1]])

        for i in range(3):
            assert not os.path.isfile('vib.{}.traj'.format(i))
        mode_traj = ase.io.read('vib.3.traj', index=':')
        assert len(mode_traj) == 5
        assert_array_almost_equal(mode_traj[0].get_all_distances(),
                                  atoms.get_all_distances())
        with pytest.raises(AssertionError):
            assert_array_almost_equal(mode_traj[4].get_all_distances(),
                                      atoms.get_all_distances())

        with open('vib.xyz', 'rt') as f:
            jmol_txt = f.read()
            assert jmol_txt == jmol_txt_ref

        assert vib.clean(empty_files=True) == 0
        assert vib.clean() == 13
        assert len(list(vib.iterimages())) == 13

        d = dict(vib.iterdisplace(inplace=False))

        for name, image in vib.iterdisplace(inplace=True):
            assert d[name] == atoms

        atoms2 = n2_emt
        vib2 = Vibrations(atoms2)
        vib2.run()

        assert_array_almost_equal(freqs, vib.get_frequencies())

        # write/read the data from another working directory
        atoms3 = n2_optimized.copy()  # No calculator needed!

        workdir = os.path.abspath(os.path.curdir)
        try:
            os.mkdir('run_from_here')
            os.chdir('run_from_here')
            vib = Vibrations(atoms3, name=os.path.join(os.pardir, 'vib'))
            assert_array_almost_equal(freqs, vib.get_frequencies())
            assert vib.clean() == 13
        finally:
            os.chdir(workdir)
            if os.path.isdir('run_from_here'):
                os.rmdir('run_from_here')
示例#8
0
    print("***Without OPTIMIZITION***\n")

else:
    print("choose only 1 or 0")

print('START FREQ CALCULATION:\n')

from ase.vibrations import Vibrations
vib = Vibrations(molecule)
vib.run()
vib.combine()
print('END OF FREQ CALCULATION\n')
print('VIBRATIONAL SUMMARY:\n')
vib.summary()
print('\nWRITING NORMAL MODE\n')
vib.write_jmol()
print('.')
print('.')
print('use JMOL for viewing of the modes')
print('.')
print('.')
print('DONE\n\n')

from ase.thermochemistry import IdealGasThermo
print("Thermochemistry DATA:\n'BY Ideal-gas limit'")
vib_energies = vib.get_energies()
potentialenergy = molecule.get_potential_energy()

thermo = IdealGasThermo(vib_energies=vib_energies,
                        potentialenergy=potentialenergy,
                        atoms=molecule,