Esempio n. 1
0
def train_ii(system, method_name, intra_temp=1000, inter_temp=300, **kwargs):
    """
    Train an intra+intermolecular from just a system

    ---------------------------------------------------------------------------
    :param system: (gt.System)

    :param method_name: (str) e.g dftb

    :param intra_temp: (float) Temperature to run the intramolecular training

    :param inter_temp: (float) Temperature to run the intermolecular training
    """

    if system.n_unique_molecules > 1:
        raise ValueError('Can only train an inter+intra for a single bulk '
                         'molecular species')

    if system.n_unique_molecules < 1:
        raise ValueError('Must have at least one molecule to train GAP for')

    if 'temp' in kwargs:
        raise ValueError('Ambiguous specification, please specify: intra_temp '
                         'and inter_temp')

    # Create a system of just the monomer to train the intra-molecular
    # component of the system
    molecule = system.molecules[0]
    intra_system = gt.System(box_size=system.box.size)
    intra_system.add_molecules(molecule)

    # and train the intra component using a bespoke GAP
    gap = gt.GAP(name=f'intra_{molecule.name}', system=intra_system)
    intra_data, _ = train(intra_system,
                          method_name=method_name,
                          gap=gap,
                          temp=intra_temp,
                          **kwargs)

    if len(intra_data) == 0:
        raise RuntimeError('Failed to train the intra-system')

    # Now create an intra GAP that has the molecule indexes
    intra_gap = gt.gap.IntraGAP(name=f'intra_{molecule.name}',
                                system=system,
                                molecule=molecule)

    inter_gap = gt.InterGAP(name=f'inter_{molecule.name}',
                            system=system)

    # And finally train the inter component of the energy
    inter_data, gap = gt.active.train(system,
                                      method_name=method_name,
                                      temp=inter_temp,
                                      gap=gt.IIGAP(intra_gap, inter_gap),
                                      **kwargs)

    return (intra_data, inter_data), gap
Esempio n. 2
0
def train_inter():
    intra_h2o_gap = gt.gap.SolventIntraGAP(name='water_intra_gap',
                                           system=system)

    intra_methane_gap = gt.gap.SoluteIntraGAP(
        name='intra_znh2o6', system=system, molecule=gt.Molecule('znh2o6.xyz'))

    inter_gap = gt.InterGAP(name='inter', system=system, default_params=False)
    inter_gap.params.soap['O'] = gt.GTConfig.gap_default_soap_params
    inter_gap.params.soap['O']['cutoff'] = 4.0
    inter_gap.params.soap['O']['other'] = ['Zn', 'H', 'O']

    gt.active.train(system,
                    method_name='gpaw',
                    validate=False,
                    max_time_active_fs=5000,
                    active_e_thresh=0.1 + 0.04 * 20,
                    gap=gt.gap.SSGAP(solute_intra=intra_methane_gap,
                                     solvent_intra=intra_h2o_gap,
                                     inter=inter_gap),
                    max_energy_threshold=5,
                    n_configs_iter=20)
    return None
Esempio n. 3
0
import gaptrain as gt
from gaptrain.solvents import get_solvent
gt.GTConfig.n_cores = 10

h2o = gt.System(box_size=[8, 8, 8])
h2o.add_solvent('h2o', n=17)

# Now create an intra GAP that has the molecule indexes
intra_gap = gt.gap.IntraGAP(name='monomer_2b_3b',
                            system=h2o,
                            molecule=get_solvent('h2o'))

inter_gap = gt.InterGAP(name=f'inter_h2o', system=h2o)
inter_gap.params.soap['O']['cutoff'] = 4.0

# And finally train the inter component of the energy
inter_data, gap = gt.active.train(h2o,
                                  method_name='cp2k',
                                  temp=300,
                                  max_energy_threshold=5,
                                  gap=gt.IIGAP(intra_gap, inter_gap),
                                  active_e_thresh=0.17)

# Run some sample MD
traj = gt.md.run_gapmd(configuration=h2o.random(min_dist_threshold=1.7),
                       gap=gap,
                       temp=300,
                       dt=0.5,
                       interval=5,
                       ps=1,
                       n_cores=4)
Esempio n. 4
0
    h2o.add_solvent('h2o', n=1)
    train_h2o()

    methane = gt.System(box_size=[10, 10, 10])
    methane.add_molecules(gt.Molecule('methane.xyz'))
    train_methane()

    system = gt.System(box_size=[10, 10, 10])
    system.add_molecules(gt.Molecule('methane.xyz'))
    system.add_solvent('h2o', n=10)

    intra_h2o_gap = gt.gap.SolventIntraGAP(name='intra_h2o', system=system)
    intra_methane_gap = gt.gap.SoluteIntraGAP(
        name='intra_methane',
        system=system,
        molecule=gt.Molecule('methane.xyz'))
    inter_gap = gt.InterGAP(name='inter', system=system)
    train_inter()

    traj = gt.md.run_gapmd(configuration=system.random(min_dist_threshold=2.0),
                           gap=gt.gap.SSGAP(solute_intra=intra_methane_gap,
                                            solvent_intra=intra_h2o_gap,
                                            inter=inter_gap),
                           temp=300,
                           dt=0.5,
                           interval=5,
                           fs=500,
                           n_cores=4)

    traj.save(filename='water_methae_traj.xyz')
Esempio n. 5
0
import gaptrain as gt
gt.GTConfig.n_cores = 4

if __name__ == '__main__':

    system = gt.System(box_size=[12.42, 12.42, 12.42])
    system.add_molecules(gt.Molecule('znh2o6.xyz', charge=2))
    system.add_solvent('h2o', n=58)

    intra_h2o_gap = gt.gap.SolventIntraGAP(name='water_intra_gap',
                                           system=system)

    intra_znh2o6_gap = gt.gap.SoluteIntraGAP(
        name='intra_znh2o6', system=system, molecule=gt.Molecule('znh2o6.xyz'))
    inter_gap = gt.InterGAP(name='inter', system=system, default_params=False)

    # Run 30 ps of dynamics from an equilibrated point
    traj = gt.md.run_gapmd(configuration=gt.Data('eqm_final_frame.xyz')[0],
                           gap=gt.gap.SSGAP(solute_intra=intra_znh2o6_gap,
                                            solvent_intra=intra_h2o_gap,
                                            inter=inter_gap),
                           temp=300,
                           dt=0.5,
                           interval=5,
                           ps=30,
                           n_cores=4)

    traj.save(filename=f'zn_h2o_traj')
Esempio n. 6
0
def train_ss(system, method_name, intra_temp=1000, inter_temp=300, **kwargs):
    """
    Train an intra+intermolecular from just a system

    ---------------------------------------------------------------------------
    :param system: (gt.System)

    :param method_name: (str) e.g dftb

    :param intra_temp: (float) Temperature to run the intramolecular training

    :param inter_temp: (float) Temperature to run the intermolecular training
    """
    if system.n_unique_molecules != 2:
        raise ValueError('Can only train an solute-solvent GAP for a system '
                         'with two molecules, the solute and the solvent')

    # Find the least, and most abundant molecules in the system, as the solute
    # and solvent respectively
    names = [mol.name for mol in system.molecules]
    nm1, nm2 = tuple(set(names))
    solute_name, solv_name = (nm1, nm2) if names.count(nm1) == 1 else (nm2, nm1)

    solute = [mol for mol in system.molecules if mol.name == solute_name][0]
    solv = [mol for mol in system.molecules if mol.name == solv_name][0]

    data = []   # List of training data for all the components in the system

    # Train the intramolecular components of the potential for the solute and
    # the solvent
    for molecule in (solute, solv):
        # Create a system with only one molecule
        intra_system = gt.System(box_size=system.box.size)
        intra_system.add_molecules(molecule)

        # and train..
        logger.info(f'Training intramolecular component of {molecule.name}')
        mol_data, _ = gt.active.train(intra_system,
                                      gap=gt.GAP(name=f'intra_{molecule.name}',
                                                 system=intra_system),
                                      method_name=method_name,
                                      temp=intra_temp,
                                      **kwargs)
        data.append(mol_data)

    # Recreate the GAPs with the full system (so they have the
    solv_gap = gt.gap.SolventIntraGAP(name=f'intra_{solv.name}', system=system)
    solute_gap = gt.gap.SoluteIntraGAP(name=f'intra_{solute.name}',
                                       system=system, molecule=solute)
    inter_gap = gt.InterGAP(name='inter', system=system)

    # and finally train the intermolecular part of the potential
    inter_data, gap = gt.active.train(system,
                                      method_name=method_name,
                                      gap=gt.gap.SSGAP(solute_intra=solute_gap,
                                                       solvent_intra=solv_gap,
                                                       inter=inter_gap),
                                      temp=inter_temp,
                                      **kwargs)
    data.append(inter_data)

    return tuple(data), gap