Esempio n. 1
0
    def __init__(self, path, cutoff, properties = [], subset=None, collect_triples = False):
        self.path = path
        self.cutoff = cutoff
        self.properties = properties
        self.collect_triples = collect_triples
        self.dbpath = os.path.join(self.path, 'icsd.db')

        environment_provider = ASEEnvironmentProvider(cutoff)

        super(ICSD, self).__init__(self.dbpath, subset, properties, environment_provider, False)
Esempio n. 2
0
    def __init__(self, path, cutoff, apikey=None, download=True, subset=None, properties=[], collect_triples=False):
        self.path = path
        self.cutoff = cutoff
        self.apikey = apikey

        if not os.path.exists(self.path):
            os.makedirs(self.path)
        self.dbpath = os.path.join(self.path, 'mp.db')

        environment_provider = ASEEnvironmentProvider(cutoff)

        if download and not os.path.exists(self.dbpath):
            self._download()

        super(MaterialsProject, self).__init__(self.dbpath, subset, properties, environment_provider, collect_triples)
Esempio n. 3
0
def neighbor_gen(at,
                 distance_expansion=None,
                 cutoff=5.0,
                 n_gaussians=25,
                 trainable_gaussians=False,
                 environment_provider=ASEEnvironmentProvider(5.0),
                 collect_triples=False,
                 pair_provider=None,
                 center_positions=True):
    properties = {}
    properties[Structure.Z] = tensor(at.numbers.astype(np.int)).unsqueeze(0)

    positions = at.positions.astype(np.float32)
    if center_positions:
        positions -= at.get_center_of_mass()
    properties[Structure.R] = tensor(positions).unsqueeze(0)

    properties[Structure.cell] = tensor(at.cell.astype(
        np.float32)).unsqueeze(0)

    # get atom environment
    idx = 0
    nbh_idx, offsets = environment_provider.get_environment(idx, at)

    properties[Structure.neighbors] = tensor(nbh_idx.astype(
        np.int)).unsqueeze(0)
    properties[Structure.cell_offset] = tensor(offsets.astype(
        np.float32)).unsqueeze(0)
    properties[Structure.neighbor_mask] = None
    properties['_idx'] = tensor(np.array([idx], dtype=np.int)).unsqueeze(0)

    if collect_triples:
        nbh_idx_j, nbh_idx_k = collect_atom_triples(nbh_idx)
        properties[Structure.neighbor_pairs_j] = tensor(
            nbh_idx_j.astype(np.int))
        properties[Structure.neighbor_pairs_k] = tensor(
            nbh_idx_k.astype(np.int))

    model = spk.custom.representation.RBF(
        distance_expansion=distance_expansion,
        cutoff=cutoff,
        n_gaussians=n_gaussians,
        trainable_gaussians=trainable_gaussians)
    model = to_device(model)
    r, f = model.forward(properties)
    return to_np(r.squeeze()), to_np(f.squeeze())
Esempio n. 4
0
    def __init__(self,
                 path,
                 cutoff,
                 properties=[],
                 subset=None,
                 collect_triples=False):
        self.path = path
        self.cutoff = cutoff
        self.properties = properties
        self.collect_triples = collect_atom_triples_offsets
        if self.path.rsplit(".", 1)[-1] == "db": self.dbpath = self.path
        else: self.dbpath = os.path.join(self.path, 'perovskites.db')

        environment_provider = ASEEnvironmentProvider(cutoff)

        super(Perovskites,
              self).__init__(self.dbpath, subset, properties,
                             environment_provider, collect_triples)
#    ax[0,2].set_xlabel('Relative error (eV/atom)',weight='bold',fontsize=14)
#    ax[1,0].hist(forces,bins=fbins,label='DFT')
#    ax[1,0].hist(forceresults,bins=fbins, color='orange',alpha=0.7,label='SchNet')
#    ax[1,0].legend()
#    ax[1,0].set_xlabel('Forces (eV/$\AA$)',weight='bold',fontsize=14)
#    ax[1,1].hist(fdiff,bins=fbins)
#    ax[1,1].set_xlabel('Error (eV/$\AA$)',weight='bold',fontsize=14)
#    ax[1,2].hist(frelative,bins=fbins)
#    ax[1,2].set_xlabel('Relative error (eV/$\AA$)',weight='bold',fontsize=14)
#    fig.suptitle('Error report for ' + file,weight='bold',fontsize=18)
#    plt.show()

device = torch.device("cuda")
train_args = args
spk.utils.set_random_seed(args.seed)
env = ASEEnvironmentProvider(args.cutoff)
#name = r'/dev/shm/data/train' + sys.argv[1]
name = r'/dev/shm/data/bulkVtrain3200'
data_train = schnetpack2.custom.datasets.extxyz1.ExtXYZ(
    name + '.db',
    name + '.xyz',
    environment_provider=env,
    properties=['energy', 'forces'])
#name = r'/dev/shm/data/test' + sys.argv[1]
name = r'/dev/shm/data/bulkVtest3200'
data_val = schnetpack2.custom.datasets.extxyz1.ExtXYZ(
    name + '.db',
    name + '.xyz',
    environment_provider=env,
    properties=['energy', 'forces'])
Esempio n. 6
0
    arr_temp = np.ctypeslib.as_array(output_ptr, shape=arr_shape)

    return arr_temp[:, :,
                    0], arr_temp[:, :,
                                 1:]  #[output_ptr[i] for i in range(N.value*max_neighbours.value*4)]#np.ctypeslib.as_array(output_ptr, shape = arr_shape) #make_nd_array(output_ptr, arr_shape)


batch_size = 16
cutoff = 5.0
apikey = None
datapath = "/scratch/leuven/412/vsc41276/mp.db"
property = "formation_energy_per_atom"

mp_ASE = AtomsData(datapath,
                   properties=[property],
                   environment_provider=ASEEnvironmentProvider(cutoff))

mp_MAARTEN = AtomsData(datapath,
                       properties=[property],
                       environment_provider=MaartenEnvironmentProvider(cutoff))

ASE_loader = spk.data.AtomsLoader(mp_ASE,
                                  batch_size=batch_size,
                                  sampler=RandomSampler(mp_ASE),
                                  num_workers=36,
                                  pin_memory=True)

MAARTEN_loader = spk.data.AtomsLoader(mp_MAARTEN,
                                      batch_size=batch_size,
                                      sampler=RandomSampler(mp_ASE),
                                      num_workers=36,