示例#1
0
    def update(self, atoms):
        """
        Connect the KIM pointers to values in the ase atoms class
        set up neighborlist and perform calculation
        """
        # here we only reinitialize the model if the number of Atoms /
        # types of atoms have changed, or if the model is uninitialized
        natoms = atoms.get_number_of_atoms()
        ntypes = len(set(atoms.get_atomic_numbers()))

        if (self.km_numberOfAtoms[0] != natoms or
            self.km_numberAtomTypes[0] != ntypes or
            self.cell_BC_changed(atoms)):
            self.set_atoms(atoms)

        if (not self.check_before_update or
            (self.check_before_update and self.calculation_required(atoms, ""))):
            # if the calculation is required we proceed to set the values
            # of the standard things each model and atom class has
            self.km_numberOfAtoms[0] = natoms
            self.km_numberAtomTypes[0] = ntypes
            self.km_coordinates[:] = atoms.get_positions().flatten()
            if self.km_particleCharge:
                km_particleCharge[:] = atoms.get_charges()

            # fill the proper chemical identifiers
            symbols = atoms.get_chemical_symbols()
            for i in range(natoms):
                self.km_atomTypes[i] = ks.KIM_API_get_species_code(self.pkim, symbols[i])

            # build the neighborlist (type depends on model set by pkim)
            if self.uses_neighbors:
                kimnl.nbl_set_cell(atoms.get_cell().flatten(), atoms.get_pbc().flatten().astype('int8'))
                kimnl.nbl_build_neighborlist(self.pkim)
            ks.KIM_API_model_compute(self.pkim)
    status = virial.virial_init(pkim)
    status = virial.set_virial(pkim)

    status = KIM_API_model_init(pkim)

    atypecode = KIM_API_get_partcl_type_code(pkim, "Ar")
    for i in range(numberOfAtoms[0]):
        atomTypes[i] = atypecode
    
    coordinates[:] = coords_dump.flatten()[:]

    KIM_API_print(pkim)

#    NNeighbors, HalfNNeighbors, neighborList, RijList = set_NeighborList(pkim, coordinates, numberOfAtoms[0], cutoff[0]*4)
#    kimneighborlist.set_neigh_object(pkim, NNeighbors, HalfNNeighbors, neighborList, RijList)
    kimneighborlist.nbl_build_neighborlist(pkim)

    KIM_API_model_compute(pkim)
except error:
    KIM_API_report_error(error.message,errno)

# print results to screen
print "--------------------------------------------------------------------------------"
print "This is Test          : %s" % testname
print "Results for KIM Model : %s" % modelname
print "Forces:"
print "Atom     X                        Y                        Z"
for i in range(numberOfAtoms[0]):
    print "%2i   %25.15e%25.15e%25.15e" % (i, forces[i*DIM + 0], forces[i*DIM + 1], forces[i*DIM + 2])
print ""
print "Energy = %20.15e" %  energy[0]