コード例 #1
0
        def __init__(self, build=True, gpuid=0, reslist=[], **kwargs):
            Calculator.__init__(self, **kwargs)

            if build:
                anipath = os.path.dirname(__file__)
                cnstfile = anipath + '/../ANI-c08f-ntwk/rHCNO-4.6A_16-3.1A_a4-8.params'
                saefile = anipath + '/../ANI-c08f-ntwk/sae_6-31gd.dat'
                nnfdir = anipath + '/../ANI-c08f-ntwk/networks/'
                self.nc = pync.molecule(cnstfile, saefile, nnfdir, gpuid)

            self.Setup = True
            self.reslist = reslist
コード例 #2
0
    def __init__(self, build=True, gpuid=0, reslist=[], **kwargs):
        Calculator.__init__(self, **kwargs)

        if build:
            anipath = os.path.dirname(__file__)
            cnstfile = anipath + '/ani-1x_dft_x8ens/rHCNO-5.2R_16-3.5A_a4-8.params'
            saefile = anipath + '/ani-1x_dft_x8ens/sae_linfit.dat'
            nnfdir = anipath + '/ani-1x_dft_x8ens//train0/networks/'
            self.nc = pync.molecule(cnstfile, saefile, nnfdir, gpuid)

        self.Setup = True
        self.reslist = reslist
コード例 #3
0
 def __init__(self,
              cnstfile,
              saefile,
              nnfprefix,
              Nnet,
              gpuid=0,
              sinet=False):
     # Number of networks
     self.Nn = Nnet
     # Construct pyNeuroChem molecule classes
     self.ncl = [
         pync.molecule(cnstfile, saefile, nnfprefix + str(i) + '/networks/',
                       gpuid, sinet) for i in range(self.Nn)
     ]
コード例 #4
0
    r = re.compile('#Smiles:(.+?)\n')
    s = r.search(f)
    return s.group(1).strip()


# Set required files for pyNeuroChem
anipath = '/home/jujuman/Dropbox/ChemSciencePaper.AER/networks/ANI-c08f-ntwk/'
cnstfile = anipath + '/rHCNO-4.6A_16-3.1A_a4-8.params'
saefile = anipath + '/sae_6-31gd.dat'
nnfdir = anipath + '/networks/'

idir = '/home/jujuman/Scratch/Research/GDB-11-wB97X-6-31gd/dnntsgdb11_07/inputs/'
sdir = '/home/jujuman/Scratch/Research/GDB-11-wB97X-6-31gd/dnntsgdb11_07/inputs_new/'

# Construct pyNeuroChem class
nc = pync.molecule(cnstfile, saefile, nnfdir, 0)

files = [f for f in os.listdir(idir) if f.split(".")[1] == "ipt"]
for i, f in enumerate(files):
    data = hdn.read_rcdb_coordsandnm(idir + f)
    X = data['coordinates']
    S = data['species']

    mol = Atoms(positions=X, symbols=S)

    mol.set_calculator(ANI(False))
    mol.calc.setnc(nc)

    dyn = LBFGS(mol, logfile='optimization.log')
    dyn.run(fmax=0.00001, steps=1000)
コード例 #5
0
def molecule_worker(task_queue, gpuid, net_list, energy, forces, net_dict):
    print('Building...')
    ncl = [
        pync.molecule(net_dict['cns'], net_dict['sae'],
                      net_dict['nnf'] + str(i) + '/networks/', gpuid, False)
        for i in net_list
    ]

    Nn = net_dict['Nn']

    if net_dict['epw']:
        for nc in ncl:
            nc.setPairWise()

    set_pbc = False

    Sp = []

    while True:
        next_task = task_queue.get()
        if next_task is None:
            # Poison pill means shutdown
            time.sleep(1)
            print('Exiting')
            task_queue.task_done()
            break

        if not set_pbc:
            pbc = next_task['pbc']
            for i, netid in enumerate(net_list):
                #print('PBC:',pbc)
                ncl[i].setPBC(pbc[0], pbc[1], pbc[2])
            set_pbc = True

        # Atomic elements
        S = next_task['S']

        # Cell
        cell = next_task['cell']

        # pbc_inv
        pinv = next_task['pinv']

        # make it two-dimensional
        for i, netid in enumerate(net_list):
            # Set the molecule/coordinates

            if Sp == S:
                if 'bynet' in next_task:
                    ncl[i].setCoordinates(
                        coords=next_task['X'][netid].astype(np.float32))
                else:
                    ncl[i].setCoordinates(
                        coords=next_task['X'].astype(np.float32))
            else:
                if 'bynet' in next_task:
                    ncl[i].setMolecule(
                        next_task['X'][netid].astype(np.float32), S)
                else:
                    ncl[i].setMolecule(next_task['X'].astype(np.float32), S)

            # Set the cell
            ncl[i].setCell(cell, pinv)
            #print('CELL:',cell)

            energy[netid] = ncl[i].energy().copy()
            forces[netid] = ncl[i].force().copy()
            #if netid == 0 and net_dict['epw']:
            #energy[netid] += ncl[i].pwenergy()
            #forces[netid] += ncl[i].pwforce()
            #print(ncl[i].pwenergy().copy())
            #print(-ncl[i].pwforce().copy()[0])

            if net_dict['epw']:
                energy[netid] += ncl[i].pwenergy()
                forces[netid] += ncl[i].pwforce()
        Sp = S

        task_queue.task_done()
    return
コード例 #6
0
import os
import ase
import pyNeuroChem
import ase_interface
import numpy

path = os.path.dirname(os.path.realpath(__file__))
builtin_path = os.path.join(path, '../../torchani/resources/ani-1x_dft_x8ens/')
const_file = os.path.join(builtin_path, 'rHCNO-5.2R_16-3.5A_a4-8.params')
sae_file = os.path.join(builtin_path, 'sae_linfit.dat')
network_dir = os.path.join(builtin_path, 'train0/networks/')
radial_length = 64
conv_au_ev = 27.21138505
all_species = ['H', 'C', 'N', 'O']
species_indices = {all_species[i]: i for i in range(len(all_species))}
nc = pyNeuroChem.molecule(const_file, sae_file, network_dir, 0)


def calc():
    calc = ase_interface.ANI(False)
    calc.setnc(nc)
    return calc


class NeuroChem:
    def _get_radial_part(self, fullaev):
        return fullaev[:, :, :radial_length]

    def _get_angular_part(self, fullaev):
        return fullaev[:, :, radial_length:]
コード例 #7
0
 def __init__(self,cnstfile,saefile,nnfdir,gpuid=0, sinet=False):
     # Construct pyNeuroChem class
     self.nc = pync.molecule(cnstfile, saefile, nnfdir, gpuid, sinet)
コード例 #8
0
smfile = '/home/jujuman/Research/RawGDB11Database/gdb11_size09.smi'  # Smiles file

wkdir = '/home/jujuman/Research/CrossValidation/'
cnstfile = wkdir + 'rHCNO-4.6A_16-3.1A_a4-8.params'
saefile = wkdir + 'sae_6-31gd.dat'

At = ['C', 'O', 'N']  # Hydrogens added after check

#-------------------------------------------
#nnfdir   = wkdir + 'cv_c08e_ntw_' + str(0) + '/networks/'

# Construct pyNeuroChem classes
#nc = pync.molecule(cnstfile, saefile, nnfdir, 0)

nc = [
    pync.molecule(cnstfile, saefile,
                  wkdir + 'cv_c08e_ntw_' + str(l) + '/networks/', 0)
    for l in range(5)
]

molecules = Chem.SmilesMolSupplier(smfile, nameColumn=0)

#mols = [molecules[i] for i in range(0,1000)]
#print(mols)
f = open(
    '/home/jujuman/Research/CrossValidation/GDB-09-High-sdev/gdb-09-0.5sdev.dat',
    'w')
for k, m in enumerate(molecules):
    if m is None: continue

    typecount = 0
コード例 #9
0
wkdir3 = '/home/jujuman/Dropbox/ChemSciencePaper.AER/networks/ANI-c08f09dd-ntwk-cv/'
wkdir4 = '/home/jujuman/Dropbox/ChemSciencePaper.AER/networks/ANI-c08f09div-ntwk-cv/'

cnstfile = 'rHCNO-4.6A_16-3.1A_a4-8.params'
saefile = 'sae_6-31gd.dat'

At = ['C', 'O', 'N']  # Hydrogens added after check

Nnc = 5

#-------------------------------------------
#nnfdir   = wkdir + 'cv_c08e_ntw_' + str(0) + '/networks/'

# Construct pyNeuroChem classes
nc1 = [
    pync.molecule(wkdir1 + cnstfile, wkdir1 + saefile,
                  wkdir1 + 'cv_c08e_ntw_' + str(l) + '/networks/', 0)
    for l in range(Nnc)
]
nc2 = [
    pync.molecule(wkdir2 + cnstfile, wkdir2 + saefile,
                  wkdir2 + 'cv_c08e_ntw_' + str(l) + '/networks/', 0)
    for l in range(Nnc)
]
nc3 = [
    pync.molecule(wkdir3 + cnstfile, wkdir3 + saefile,
                  wkdir3 + 'cv_c08e_ntw_' + str(l) + '/networks/', 0)
    for l in range(Nnc)
]
nc4 = [
    pync.molecule(wkdir4 + cnstfile, wkdir4 + saefile,
                  wkdir4 + 'cv_c08e_ntw_' + str(l) + '/networks/', 0)
コード例 #10
0
ファイル: cv_md_run.py プロジェクト: zubatyuk/ANI-Tools
cnstfile = wkdir + 'rHCNO-4.6A_16-3.1A_a4-8.params'
saefile = wkdir + 'sae_6-31gd.dat'

At = ['C', 'O', 'N']  # Hydrogens added after check

T = 800.0
dt = 0.25

stdir = '/home/jujuman/Research/CrossValidation/MD_CV/'

#-------------------------------------------

# Construct pyNeuroChem classes
print('Constructing CV network list...')
ncl = [
    pync.molecule(cnstfile, saefile, wkdir + 'train' + str(l) + '/networks/',
                  0, False) for l in range(5)
]
print('Complete.')

# Set required files for pyNeuroChem
#anipath  = '/home/jujuman/Dropbox/ChemSciencePaper.AER/ANI-c08e-ccdissotest1-ntwk'
#cnstfile = anipath + '/rHCNO-4.6A_16-3.1A_a4-8.params'
#saefile  = anipath + '/sae_6-31gd.dat'
#nnfdir   = anipath + '/networks/'

# Construct pyNeuroChem class
print('Constructing MD network...')
nc = ncl[1]
#nc = pync.molecule(cnstfile, saefile, nnfdir, 0)
print('FINISHED')
コード例 #11
0
def plot_irc_data(axes, file, rcf, title):
    xyz, typ, Eact = hdt.readncdat(file, np.float32)
    Rc = np.load(rcf)

    # Set required files for pyNeuroChem
    wkdir = '/home/jujuman/Dropbox/ChemSciencePaper.AER/networks/ANI-c08f-ntwk-cv/'
    cnstfile = 'rHCNO-4.6A_16-3.1A_a4-8.params'
    saefile = 'sae_6-31gd.dat'

    nc = [
        pync.conformers(wkdir + cnstfile, wkdir + saefile,
                        wkdir + 'cv_c08e_ntw_' + str(l) + '/networks/', 0)
        for l in range(5)
    ]

    rcdir = '/home/jujuman/Research/ANI-DATASET/RXN1_TNET/training/rxn1to6/ani_benz_rxn_ntwk/'
    ncr1 = pync.conformers(rcdir + '../../' + cnstfile,
                           rcdir + '../../' + saefile, rcdir + '/networks/', 0)
    ncr2 = pync.molecule(rcdir + '../../' + cnstfile,
                         rcdir + '../../' + saefile, rcdir + '/networks/', 0)
    ncr3 = pync.molecule(rcdir + '../../' + cnstfile,
                         rcdir + '../../' + saefile, rcdir + '/networks/', 0)

    # Compute reactant E
    ncr2.setMolecule(coords=xyz[0], types=list(typ))
    Er = ncr2.energy()

    # Compute product E
    ncr3.setMolecule(coords=xyz[-1], types=list(typ))
    Ep = ncr3.energy()

    #Eact = Eact[::-1]

    dE_ani = hdt.hatokcal * (Er - Ep)
    dE_dft = hdt.hatokcal * (Eact[0] - Eact[-1])
    print('Delta E R/P ANI:', dE_ani, 'Delta E R/P ANI:', dE_dft, 'Diff:',
          abs(dE_ani - dE_dft))

    # Set the conformers in NeuroChem
    ncr1.setConformers(confs=xyz, types=list(typ))

    # Compute Energies of Conformations
    E1 = ncr1.energy()

    # Shift
    E1 = E1 - E1[0]
    Eact = Eact - Eact[0]

    # Plot
    errn = hdt.calculaterootmeansqrerror(hdt.hatokcal * E1,
                                         hdt.hatokcal * Eact)
    axes.plot(Rc['x'][:, 1],
              hdt.hatokcal * (E1),
              color='red',
              label="{:.2f}".format(errn),
              linewidth=2)

    axes.plot(Rc['x'][:, 1],
              hdt.hatokcal * (Eact),
              'r--',
              color='black',
              linewidth=3)

    err = []

    for n, net in enumerate(nc):
        # Set the conformers in NeuroChem
        net.setConformers(confs=xyz, types=list(typ))

        # Compute Energies of Conformations
        E1 = net.energy()
        E1 = E1 - E1[0]

        err.append(
            hdt.calculaterootmeansqrerror(hdt.hatokcal * E1,
                                          hdt.hatokcal * Eact))

        # Plot
        if n == len(nc) - 1:
            mean = np.mean(np.asarray(err))
            axes.plot(Rc['x'][:, 1],
                      hdt.hatokcal * (E1),
                      color='blue',
                      label="{:.2f}".format(mean),
                      linewidth=1)
        else:
            axes.plot(Rc['x'][:, 1],
                      hdt.hatokcal * (E1),
                      color='blue',
                      linewidth=1)

            axes.plot(Rc['x'][:, 1],
                      hdt.hatokcal * (E1),
                      color='blue',
                      linewidth=1)

    axes.set_xlim([Rc['x'][:, 1].min(), Rc['x'][:, 1].max()])
    axes.legend(loc="upper right", fontsize=8)
    axes.set_title(title)
    return np.array([errn, np.mean(err)])