Пример #1
0
def vib(struct, proj_path):
    #struct.calc = Gaussian(label='calc/' + proj_name + '/freq',
    #                        freq='')
    print("\nBeginning calculation of IR frequencies...")

    struct.calc = Gaussian(mem='4GB',
                    nprocshared='8',
                    label=proj_path + '/vib',
                    )
    #struct.get_potential_energy()
    ir = Infrared(struct)
    ir.run()
    ir.write_spectra('ir_spectra.dat')
    spectrum = ir.get_spectrum()
    ir.clean() # to get rid of disturbing .pckl files cluttering the directory
    print("Calculation of vibrational frequencies completed!\nPrinting spectrum...")

    return struct, spectrum
Пример #2
0
def test_folding(testdir):
    """Test that folding is consitent with intensities"""
    
    atoms = molecule('C2H6')
    atoms.calc = RandomCalculator()
    ir = Infrared(atoms)
    ir.run()
    freqs = ir.get_frequencies().real

    for folding in ['Gaussian', 'Lorentzian']:
        x, y = ir.get_spectrum(start=freqs.min() - 100,
                               end=freqs.max() + 100,
                               type=folding,
                               normalize=True)
        assert ir.intensities.sum() == pytest.approx(
            y.sum() * (x[1] - x[0]), 1e-2)
Пример #3
0
def test_combine(testdir):
    dirname = 'subdir'
    vibname = 'ir'
    with workdir(dirname, mkdir=True):
        atoms = molecule('C2H6')
        ir = Infrared(atoms)
        assert ir.name == vibname
        ir.calc = RandomCalculator()
        ir.run()
        freqs = ir.get_frequencies()
        ints = ir.intensities
        assert ir.combine() == 49

        ir = Infrared(atoms)
        assert (freqs == ir.get_frequencies()).all()
        assert (ints == ir.intensities).all()

        vib = Vibrations(atoms, name=vibname)
        assert (freqs == vib.get_frequencies()).all()

        # Read the data from other working directory
        with workdir('..'):
            ir = Infrared(atoms, name=f'{dirname}/{vibname}')
            assert (freqs == ir.get_frequencies()).all()

        ir = Infrared(atoms)
        assert ir.split() == 1
        assert (freqs == ir.get_frequencies()).all()
        assert (ints == ir.intensities).all()

        vib = Vibrations(atoms, name=vibname)
        assert (freqs == vib.get_frequencies()).all()

        assert ir.clean() == 49
Пример #4
0
alpha_back = 0.70
alpha_front = 1.0

for i, atoms in enumerate(ga_stru):
    e = atoms.get_potential_energy()
    Gs_slab[i] = e
    colors[i] = color_lib[i]
# vibrational frequency calculations
calc = GPAW(mode=PW(500),
            xc='PBE',
            spinpol=True,
            kpts=(2, 2, 1),
            symmetry={'point_group': False},
            basis='dzp')
O2.set_calculator(calc)
O2vib = Infrared(O2)
#print(O2vib)
#O2vib.run()
#O2vib.summary()
e_O2vib = O2vib.get_energies()
#print(e_O2vib)

thermo = IdealGasThermo(vib_energies=e_O2vib,
                        atoms=O2,
                        geometry='linear',
                        symmetrynumber=2,
                        spin=1)


#print(e_O2vib)
def get_mu(T, p):
Пример #5
0
class RandomCalculator():
    """Fake Calculator class.

    """
    def __init__(self):
        self.rng = RandomState(42)

    def get_forces(self, atoms):
        return self.rng.rand(len(atoms), 3)

    def get_dipole_moment(self, atoms):
        return self.rng.rand(3)


atoms = molecule('C2H6')
ir = Infrared(atoms)
ir.calc = RandomCalculator()
ir.run()
freqs = ir.get_frequencies()
ints = ir.intensities
assert ir.combine() == 49

ir = Infrared(atoms)
assert (freqs == ir.get_frequencies()).all()
assert (ints == ir.intensities).all()

vib = Vibrations(atoms, name='ir')
assert (freqs == vib.get_frequencies()).all()

# Read the data from other working directory
dirname = os.path.basename(os.getcwd())
Пример #6
0
def test_combine():
    import os
    from numpy.random import RandomState

    from ase.build import molecule
    from ase.vibrations import Vibrations
    from ase.vibrations import Infrared


    class RandomCalculator():
        """Fake Calculator class.

        """
        def __init__(self):
            self.rng = RandomState(42)

        def get_forces(self, atoms):
            return self.rng.rand(len(atoms), 3)

        def get_dipole_moment(self, atoms):
            return self.rng.rand(3)


    atoms = molecule('C2H6')
    ir = Infrared(atoms)
    ir.calc = RandomCalculator()
    ir.run()
    freqs = ir.get_frequencies()
    ints = ir.intensities
    assert ir.combine() == 49

    ir = Infrared(atoms)
    assert (freqs == ir.get_frequencies()).all()
    assert (ints == ir.intensities).all()

    vib = Vibrations(atoms, name='ir')
    assert (freqs == vib.get_frequencies()).all()

    # Read the data from other working directory
    dirname = os.path.basename(os.getcwd())
    os.chdir('..')  # Change working directory
    ir = Infrared(atoms, name=os.path.join(dirname, 'ir'))
    assert (freqs == ir.get_frequencies()).all()
    os.chdir(dirname)

    ir = Infrared(atoms)
    assert ir.split() == 1
    assert (freqs == ir.get_frequencies()).all()
    assert (ints == ir.intensities).all()

    vib = Vibrations(atoms, name='ir')
    assert (freqs == vib.get_frequencies()).all()

    assert ir.clean() == 49
Пример #7
0
class RandomCalculator():
    """Fake Calculator class.

    """
    def __init__(self):
        self.rng = RandomState(42)

    def get_forces(self, atoms):
        return self.rng.rand(len(atoms), 3)

    def get_dipole_moment(self, atoms):
        return self.rng.rand(3)


atoms = molecule('C2H6')
ir = Infrared(atoms)
ir.calc = RandomCalculator()
ir.run()
freqs = ir.get_frequencies()
ints = ir.intensities
assert ir.combine() == 49

ir = Infrared(atoms)
assert (freqs == ir.get_frequencies()).all()
assert (ints == ir.intensities).all()

vib = Vibrations(atoms, name='ir')
assert (freqs == vib.get_frequencies()).all()

ir = Infrared(atoms)
assert ir.split() == 1
Пример #8
0
from ase.db import connect
import os


for i in range(133885):
    try:
        print('-' * 100, i)
        # os.system('ls | grep -v water.py | grep -v qm9*.db | xargs rm')
        os.system('rm -rf *.pckl vasprun.xml')
        a = read('qm9.db@' + str(i))
        a.set_cell([10, 10, 10])
        a.set_pbc([1, 1, 1])
        
        calc = Vasp(prec='Accurate',
            ediff=1E-8,
            isym=0,
            idipol=4,       # calculate the total dipole moment
            dipol=a.get_center_of_mass(scaled=True),
            ldipol=True,
            kpts=[1, 1, 1])
        
        a.calc = calc
        ir = Infrared(a)
        ir.run()
        ir.summary()
        with connect('qm9_ir_spectrum.db') as db:
            db.write(a, data={'ir_spectrum':ir.get_spectrum()})
            # print(ir.get_spectrum()[0].shape)
    except:
        pass