Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: not enough values to unpack (expected 3, got 2) #27

Open
miroi opened this issue Jul 5, 2024 · 2 comments
Open

ValueError: not enough values to unpack (expected 3, got 2) #27

miroi opened this issue Jul 5, 2024 · 2 comments

Comments

@miroi
Copy link

miroi commented Jul 5, 2024

Hello,

I took this kimpy example, https://openkim.org/doc/usage/using-models/#Python

and git this error with fresh pip installed kimpy:

python3 kimpy_example.py
Traceback (most recent call last):
  File "/mnt/c/Users/milias/Documents/git-projects/open-collection/theoretical_chemistry/software/openkim/buildup_on_servers/jinr_ru/wsl_win10_pc7321b/kimpy_example/kimpy_example.py", line 33, in <module>
    requestedUnitsAccepted, kim_model, _ = kimpy.model.create(
ValueError: not enough values to unpack (expected 3, got 2)
@mjwen
Copy link
Collaborator

mjwen commented Jul 6, 2024

Hi @miroi!

Thanks for reporting this! I can reproduce the error. The script on the KIM website was for an older version of kimpy before 2.0. I've updated it to be compatible with the latest kimpy. Will update the KIM website soon. Please find the updated code below.

Also, you might find some of the tests here useful. Although they are not examples, they show many of the functionality and usages.

"""An example to use kimpy to compute the energy vs. distance of a copper dimer."""

import numpy as np
import kimpy


# Callback routine for the KIM API to get atom neighbor lists
def get_neigh(data_in, cutoffs_in, neighbor_list_index_in, particle_number_in):
    neighbors = data_in["neighbors"][particle_number_in]
    return (neighbors, 0)


# Function to construct neighbor lists for the atoms.
# (This is a highly-inefficient N^2 algorithm that should only be used for
# small numbers of atoms.)
# For larger systems, you might want to use kimpy.neighlist.
def create_neigh(coords_in, cutoff, neigh_in):
    n = coords_in.shape[0]
    neighbors = []
    for i in range(n):
        neigh_i = []
        for j in range(n):
            if j == i:
                continue
            dist = np.linalg.norm(coords_in[i] - coords_in[j])
            if dist < cutoff:
                neigh_i.append(j)
        neigh_i = np.array(neigh_i, dtype=np.intc)
        neighbors.append(neigh_i)
    neigh_in["cutoff"] = cutoff
    neigh_in["num_particles"] = n
    neigh_in["neighbors"] = neighbors


# Initialize KIM potential specifying the units requested from the potential.
modelname = "EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005"
units_accepted, kim_model = kimpy.model.create(
    kimpy.numbering.zeroBased,
    kimpy.length_unit.A,
    kimpy.energy_unit.eV,
    kimpy.charge_unit.e,
    kimpy.temperature_unit.K,
    kimpy.time_unit.ps,
    modelname,
)


# Define simulation arguments
N = 2
coords = np.zeros((N, 3), dtype=np.double)
forces = np.zeros((N, 3), dtype=np.double)
energy = np.array([0.0], dtype=np.double)
num_particles = np.array([N], dtype=np.intc)
species_code = np.zeros(num_particles, dtype=np.intc)
particle_contributing = np.zeros(num_particles, dtype=np.intc)

# Set KIM API pointers to simulation arguments
compute_arguments = kim_model.compute_arguments_create()
compute_arguments.set_argument_pointer(
    kimpy.compute_argument_name.numberOfParticles, num_particles
)
compute_arguments.set_argument_pointer(
    kimpy.compute_argument_name.particleSpeciesCodes, species_code
)
compute_arguments.set_argument_pointer(
    kimpy.compute_argument_name.particleContributing, particle_contributing
)
compute_arguments.set_argument_pointer(kimpy.compute_argument_name.coordinates, coords)
compute_arguments.set_argument_pointer(
    kimpy.compute_argument_name.partialEnergy, energy
)
compute_arguments.set_argument_pointer(
    kimpy.compute_argument_name.partialForces, forces
)

# Setup neighbor lists through KIM API callback mechanism
neigh = dict()
compute_arguments.set_callback(
    kimpy.compute_callback_name.GetNeighborList, get_neigh, neigh
)

# Setup for calculation
influence_dist = kim_model.get_influence_distance()
supported, code = kim_model.get_species_support_and_code(kimpy.species_name.Al)
species_code[:] = code
particle_contributing[:] = 1

# Loop over dimer energy
print("  Distance", " " * 9, "Energy")
for z in np.arange(1.0, np.ceil(influence_dist) + 0.5, 0.5):
    coords[1, 2] = z
    create_neigh(coords, influence_dist, neigh)
    kim_model.compute(compute_arguments)
    print("{:18.10e} {:18.10e}".format(z, energy[0]))

@miroi
Copy link
Author

miroi commented Jul 18, 2024

Thanks ! This works.

milias@Miro:/mnt/c/Users/miroi/OneDrive/Desktop/Work/projekty/open-collection/theoretical_chemistry/software/openkim-ase/runs/kimpy_example/.python3 kimpy_example.py
  Distance           Energy
  1.0000000000e+00   8.3309698035e+00
  1.5000000000e+00   4.0612306870e+00
  2.0000000000e+00   1.8021700693e-02
  2.5000000000e+00  -1.9353325249e+00
  3.0000000000e+00  -1.7714986219e+00
  3.5000000000e+00  -1.1478765871e+00
  4.0000000000e+00  -4.9042072724e-01
  4.5000000000e+00  -2.0418576357e-01
  5.0000000000e+00  -1.1762679400e-01
  5.5000000000e+00  -5.0038462875e-03
  6.0000000000e+00   0.0000000000e+00

We can close this ticket as solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants