Beispiel #1
0
def check_hessian_bonds(name, tol=1e-3 * kjmol / angstrom**2):
    with log.section('NOSETST', 2):
        system, ref = read_system(name)
        set_ffatypes(system, 'highest')
        valence = ValenceFF(system, Settings())
    for term in valence.iter_terms('BONDHARM'):
        inonzero, izero = get_indices_zero_nonzero(term, len(system.numbers))
        rv = np.random.uniform(low=1.00, high=2.00) * angstrom
        fc = np.random.uniform(low=1000, high=3000) * kjmol / angstrom**2
        ref, num = get_analytic_numeric_hessian(valence, term, fc=fc, rv0=rv)
        #assert that hessian elements of atoms not part of the current bond
        #are zero
        if len(izero[0]) > 0:
            assert (abs(ref[izero])).max() < 1e-12 * kjmol / angstrom**2
            assert (abs(num[izero])).max() < 1e-12 * kjmol / angstrom**2
        M = (abs(ref - num)).max()
        iM, jM = np.where(abs(ref - num) == M)[0][0], np.where(
            abs(ref - num) == M)[1][0]
        print(
            '%25s (random FC=%8.3f kjmol/A^2    RV=%7.3f A  ):  MaxDev(%2i,%2i)=%.3e kjmol/A^2'
            % (term.basename, fc /
               (kjmol / angstrom**2), rv / angstrom, iM, jM, M /
               (kjmol / angstrom**2)))
        assert M < tol
    del system, valence, ref, num
Beispiel #2
0
def check_hessian_dihedrals(name, tol=1e-3 * kjmol / angstrom**2):
    with log.section('NOSETST', 2):
        system, ref = read_system(name)
        set_ffatypes(system, 'highest')
        valence = ValenceFF(system, Settings())
    ref, num = None, None
    for term in valence.iter_terms('TORS'):
        psi0 = get_dihedral_angle(term, system)
        inonzero, izero = get_indices_zero_nonzero(term, len(system.numbers))
        rv = np.random.uniform(low=0, high=180) * deg  #q0
        fc = np.random.uniform(low=10, high=50) * kjmol
        ref, num = get_analytic_numeric_hessian(valence, term, fc=fc, rv0=rv)
        #assert that hessian elements of atoms not part of the current dihedral
        #are zero
        if len(izero[0]) > 0:
            assert (abs(ref[izero])).max() < 1e-12 * kjmol / angstrom**2
            assert (abs(num[izero])).max() < 1e-12 * kjmol / angstrom**2
        M = (abs(ref - num)).max()
        iM, jM = np.where(abs(ref - num) == M)[0][0], np.where(
            abs(ref - num) == M)[1][0]
        print(
            '%25s (eq=%.1f deg    random FC=%8.3f kjmol        RV=%7.3f deg):  MaxDev(%2i,%2i)=%.3e kjmol/A^2'
            % (term.basename, psi0 / deg, fc / kjmol, rv / deg, iM, jM, M /
               (kjmol / angstrom**2)))
        assert M < tol
    del system, valence, ref, num
Beispiel #3
0
    def __init__(self, system, ai, settings, ffrefs=[]):
        '''
            **Arguments**

            system
                a Yaff `System` instance defining the system

            ai
                a `Reference` instance corresponding to the ab initio input data

            settings
                a `Settings` instance defining all QuickFF settings

            **Optional Arguments**

            ffrefs
                a list of `Reference` instances defining the a-priori force
                field contributions.
        '''
        with log.section('INIT', 1, timer='Initializing'):
            log.dump('Initializing program')
            self.settings = settings
            self.system = system
            self.ai = ai
            self.ffrefs = ffrefs
            self.valence = ValenceFF(system, settings)
            self.perturbation = RelaxedStrain(system, self.valence, settings)
            self.trajectories = None
            self.print_system()
Beispiel #4
0
def check_hessian_dihedrals(name, tol=1e-3 * kjmol / angstrom**2):
    with log.section('NOSETST', 2):
        system, ref = read_system(name)
        guess_ffatypes(system, 'highest')
        valence = ValenceFF(system)
    for term in valence.iter_terms('TORSION'):
        psi0 = get_dihedral_angle(term, system)
        inonzero, izero = get_indices_zero_nonzero(term, len(system.numbers))
        rv = np.random.uniform(low=0, high=180) * deg  #q0
        fc = np.random.uniform(low=10, high=50) * kjmol
        ref, num = get_analytic_numeric_hessian(valence, term, fc=fc, rv0=rv)
        #assert that hessian elements of atoms not part of the current dihedral
        #are zero
        if len(izero[0]) > 0:
            assert (abs(ref[izero])).max() < 1e-12 * kjmol / angstrom**2
            assert (abs(num[izero])).max() < 1e-12 * kjmol / angstrom**2
        M = (abs(ref - num)).max()
        iM, jM = np.where(abs(ref - num) == M)[0][0], np.where(
            abs(ref - num) == M)[1][0]
        print '%25s (eq=%.1f deg    random FC=%8.3f kjmol        RV=%7.3f deg):  MaxDev(%2i,%2i)=%.3e kjmol/A^2' % (
            term.basename, psi0 / deg, fc / kjmol, rv / deg, iM, jM, M /
            (kjmol / angstrom**2))
        if abs(abs(psi0) - 180 * deg) < 1 * deg or abs(psi0) < 1 * deg:
            print ' ==> SKIPPED due to instable numerical implementation of derivatives in Yaff for values dihedrals to 0 or 180 deg'
        else:
            assert M < tol
    del system, valence, ref, num
Beispiel #5
0
def check_terms(name):
    'Check whether all ICs are present in ValenceFF instance'
    #TODO: CROSS terms
    with log.section('NOSETST', 2):
        system, ref = read_system(name)
        guess_ffatypes(system, 'high')
        valence = ValenceFF(system)
    #check if every bond is present and harmonic
    for bond in system.iter_bonds():
        found = False
        for term in valence.iter_terms('BONDHARM'):
            at0, at1 = term.get_atoms()
            if bond[0]==at0 and bond[1]==at1 \
            or bond[0]==at1 and bond[1]==at0:
                assert not found, 'BondHarm term %s was already found!' % str(
                    bond)
                found = True
        assert found, 'No BondHarm term found for bond %s' % str(bond)
    #check if every bend is present
    for angle in system.iter_angles():
        found = False
        for term in valence.iter_terms('BENDAHARM'):
            at0, at1, at2 = term.get_atoms()
            if angle[0]==at0 and angle[1]==at1 and angle[2]==at2 \
            or angle[0]==at2 and angle[1]==at1 and angle[2]==at0:
                assert not found, 'BendAHarm term %s was already found!' % str(
                    angle)
                found = True
        assert found, 'No BendAHarm term found for bond %s' % str(angle)
    #check if every dihedral is present
    for dihed in system.iter_dihedrals():
        found = False
        for term in valence.iter_terms('TORSION'):
            at0, at1, at2, at3 = term.get_atoms()
            if dihed[0]==at0 and dihed[1]==at1 and dihed[2]==at2 and dihed[3]==at3\
            or dihed[0]==at3 and dihed[1]==at2 and dihed[2]==at1 and dihed[3]==at0:
                assert not found, 'Torsion term %s was already found!' % str(
                    dihed)
                found = True
        assert found, 'No Torsion term found for bond %s' % str(dihedral)
    #check if every oop distance is present and Harm for rv of 0 and SQHARM else
    for oop in system.iter_oops():
        found = False
        for term in valence.iter_terms('/OOPDIST'):
            at0, at1, at2, at3 = term.get_atoms()
            for p0, p1, p2 in permutations([at0, at1, at2]):
                if oop[0] == p0 and oop[1] == p1 and oop[2] == p2 and oop[
                        3] == at3:
                    assert not found, 'OopDist term %s was already found!' % str(
                        oop)
                    found = True
        for term in valence.iter_terms('SQOOPDIST'):
            at0, at1, at2, at3 = term.get_atoms()
            for p0, p1, p2 in permutations([at0, at1, at2]):
                if oop[0] == p0 and oop[1] == p1 and oop[2] == p2 and oop[
                        3] == at3:
                    assert not found, 'SqOopDist term %s was already found!' % str(
                        oop)
                    found = True
        assert found, 'No (Sq)OopDist term found for bond %s' % str(oop)
Beispiel #6
0
    def __init__(self, system, ai, **kwargs):
        '''
            **Arguments**

            system
                a Yaff `System` object defining the system

            ai
                a `Reference` instance corresponding to the ab initio input data

            **Keyword Arguments**

            ffrefs
                a list of `Reference` objects corresponding to a priori determined
                contributions to the force field (such as eg. electrostatics
                or van der Waals contributions)

            fn_yaff
                the name of the file to write the final parameters to in Yaff
                format. The default is `pars.txt`.

            fn_sys
                the name of the file to write the system to. The default is
                `system.chk`.

            fn_traj
                a cPickle filename to read/write the perturbation trajectories
                from/to. If the file exists, the trajectories are read from the
                file. If the file does not exist, the trajectories are written
                to the file.

            only_traj
                specifier to determine for which terms a perturbation trajectory
                needs to be constructed. If ONLY_TRAJ is a single string, it is
                interpreted as a task (only terms that have this task in their
                tasks attribute will get a trajectory). If ONLY_TRAJ is a list
                of strings, each string is interpreted as the basename of the
                term for which a trajectory will be constructed.

            plot_traj
                if set to True, all energy contributions along each perturbation
                trajectory will be plotted using the final force field.

            xyz_traj
                if set to True, each perturbation trajectory will be written to
                an XYZ file.
        '''
        with log.section('PROG', 2, timer='Initializing'):
            log.dump('Initializing program')
            self.system = system
            self.ai = ai
            self.kwargs = kwargs
            self.valence = ValenceFF(system)
            self.perturbation = RelaxedStrain(system, self.valence)
            self.trajectories = None
Beispiel #7
0
def check_hessian_oops(name, tol=1e-3 * kjmol / angstrom**2):
    with log.section('PROGRAM', 2):
        system, ref = read_system(name)
        guess_ffatypes(system, 'highest')
        valence = ValenceFF(system)
    for term in valence.iter_terms('/OOPDIST'):
        inonzero, izero = get_indices_zero_nonzero(term, len(system.numbers))
        rv = 0.0
        fc = np.random.uniform(low=500, high=5000) * kjmol / angstrom**2
        ref, num = get_analytic_numeric_hessian(valence, term, fc=fc, rv0=rv)
        #assert that hessian elements of atoms not part of the current oop
        #are zero
        if len(izero[0]) > 0:
            assert (abs(ref[izero])).max() < 1e-12 * kjmol / angstrom**2
            assert (abs(num[izero])).max() < 1e-12 * kjmol / angstrom**2
        M = (abs(ref - num)).max()
        iM, jM = np.where(abs(ref - num) == M)[0][0], np.where(
            abs(ref - num) == M)[1][0]
        print '%25s (random FC=%8.3f kjmol/A^2    RV=%7.3f A  ):  MaxDev(%2i,%2i)=%.3e kjmol/A^2' % (
            term.basename, fc /
            (kjmol / angstrom**2), rv / angstrom, iM, jM, M /
            (kjmol / angstrom**2))
        assert M < tol
    for term in valence.iter_terms('SQOOPDIST'):
        inonzero, izero = get_indices_zero_nonzero(term, len(system.numbers))
        rv = np.random.uniform(low=0.01, high=0.1) * angstrom**2
        fc = np.random.uniform(low=500, high=5000) * kjmol / angstrom**4
        ref, num = get_analytic_numeric_hessian(valence, term, fc=fc, rv0=rv)
        #assert that hessian elements of atoms not part of the current oop
        #are zero
        if len(izero[0]) > 0:
            assert (abs(ref[izero])).max() < 1e-12 * kjmol / angstrom**2
            assert (abs(num[izero])).max() < 1e-12 * kjmol / angstrom**2
        M = (abs(ref - num)).max()
        iM, jM = np.where(abs(ref - num) == M)[0][0], np.where(
            abs(ref - num) == M)[1][0]
        print '%25s (random FC=%8.3f kjmol/A^4    RV=%7.3f A^2):   MaxDev(%2i,%2i)=%.3e kjmol/A^2' % (
            term.basename, fc /
            (kjmol / angstrom**4), rv / angstrom**2, iM, jM, M /
            (kjmol / angstrom**2))
        assert M < tol
    del system, valence, ref, num