Skip to content

Enforce C contiguous array order for NumPy array #49

@kjelljorner

Description

@kjelljorner

While using xtb-python together with PySCF, I noticed a strange behaviour. Different energies would be obtained whether I got the coordinates from the PySCF Mole object or read them myself from an xyz file. I think the problem here is that PySCF uses F contiguous arrays, while xtb-python expects C contiguous. The problem is fixed by changing the order with np.ascontiguousarray. I guess that ideally this check + conversion should be done on the xib-python side.

mol = gto.Mole(verbose=0, basis="def2svp").fromfile("xtbopt.xyz", format="xyz")
elements = mol.atom_charges()
coordinates = mol.atom_coords()
coordinates.flags
  C_CONTIGUOUS : False
  F_CONTIGUOUS : True
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False
  UPDATEIFCOPY : False
calc_r = Calculator(get_method("GFNFF"), elements, coordinates)
results = calc_r.singlepoint()
results.get_energy()
5.134599834832412
coordinates = np.ascontiguousarray(mol.atom_coords())
coordinates.flags
  C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False
  UPDATEIFCOPY : False
calc_r = Calculator(get_method("GFNFF"), elements, coordinates)
results = calc_r.singlepoint()
results.get_energy()
-4.0651143277974615

xtbopt.xyz.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions