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

describer.py line 247 en.join(orientations): ValidationError Input should be a valid string #433

Closed
ViktoriiaBaib opened this issue Feb 8, 2024 · 4 comments

Comments

@ViktoriiaBaib
Copy link

Hi,

When calling:

from pymatgen.core import Structure
from robocrys import StructureCondenser
from robocrys import StructureDescriber

structure = Structure.from_file("C.cif")
sc = StructureCondenser()
describer = StructureDescriber()
condensed_structure = sc.condense_structure(structure)
description = describer.describe(condensed_structure)

I was having this error:

File ".../robocrys/describe/describer.py", line 247, in get_component_makeup_summary
en.join(orientations), s_direction
File ".../pydantic/_internal/_validate_call.py", line 100, in __call__
res = self.__pydantic_validator__.validate_python(pydantic_core.ArgsKwargs(args, kwargs))
pydantic_core._pydantic_core.ValidationError: 1 validation error for join
0.0
Input should be a valid string [type=string_type, input_value=(0, 0, 1), input_type=tuple]
For further information visit https://errors.pydantic.dev/2.4/v/string_type

Fix that helped in describer.py lines 241-249 is adding orientations_str:

               if component_group.dimensionality in [1, 2]:
                    orientations = list(
                        {c.orientation for c in component_group.components}
                    )
                    orientations_str = [str(o) for o in orientations]
                    s_direction = en.plural("direction", len(orientations))
                    comp_desc += " oriented in the {} {}".format(
                        en.join(orientations_str), s_direction
                    )

I am using Python 3.10.13 and the following package versions:
matminer 0.9.1.dev5
monty 2023.11.3
pydantic 2.4.2
pydantic_core 2.10.1
pydantic-settings 2.1.0
pymatgen 2023.3.23
robocrys 0.2.8
ruamel.yaml 0.17.40
ruamel.yaml.clib 0.2.7

And that is my "C.cif" file:

# generated using pymatgen
data_C
_symmetry_space_group_name_H-M   P6/mmm
_cell_length_a   2.46803014
_cell_length_b   2.46803014
_cell_length_c   19.99829300
_cell_angle_alpha   90.00000000
_cell_angle_beta   90.00000000
_cell_angle_gamma   120.00000000
_symmetry_Int_Tables_number   191
_chemical_formula_structural   C
_chemical_formula_sum   C2
_cell_volume   105.49320255
_cell_formula_units_Z   2
loop_
 _symmetry_equiv_pos_site_id
 _symmetry_equiv_pos_as_xyz
  1  'x, y, z'
  2  '-x, -y, -z'
  3  'x-y, x, z'
  4  '-x+y, -x, -z'
  5  '-y, x-y, z'
  6  'y, -x+y, -z'
  7  '-x, -y, z'
  8  'x, y, -z'
  9  '-x+y, -x, z'
  10  'x-y, x, -z'
  11  'y, -x+y, z'
  12  '-y, x-y, -z'
  13  '-y, -x, -z'
  14  'y, x, z'
  15  '-x, -x+y, -z'
  16  'x, x-y, z'
  17  '-x+y, y, -z'
  18  'x-y, -y, z'
  19  'y, x, -z'
  20  '-y, -x, z'
  21  'x, x-y, -z'
  22  '-x, -x+y, z'
  23  'x-y, -y, -z'
  24  '-x+y, y, z'
loop_
 _atom_site_type_symbol
 _atom_site_label
 _atom_site_symmetry_multiplicity
 _atom_site_fract_x
 _atom_site_fract_y
 _atom_site_fract_z
 _atom_site_occupancy
  C  C0  2  0.33333333  0.66666667  0.00000000  1

Could you look into this please?

@zakidotai
Copy link

zakidotai commented Feb 14, 2024

This error also occurs in
pydantic==2.6.1 pydantic-settings==2.1.0

all other versions are the same as above.

@rookiexiong7
Copy link

hello! I encountered the same problem, how did you solve it?

@Grenzlinie
Copy link

Grenzlinie commented Apr 6, 2024

This is because variable "orientations_str" is None and the en module need the "orientations_str" has a value.
For example,
condenser = StructureCondenser().
describer = StructureDescriber()
structure = Structure.from_file("DyBi2IO4.cif")
condensed_structure = condenser.condense_structure(structure)
for k,v in condensed_structure.items():
print(k, v)
You will get:
components {0: {'formula': 'Dy(BiO2)2', 'dimensionality': 2, 'orientation': (0, 0, 1), 'molecule_name': None, 'sites': [0, 1, 1, 4, 4, 4, 4]}, 1: {'formula': 'I', 'dimensionality': 0, 'orientation': None, 'molecule_name': 'hydriodic acid', 'sites': [3]}}.

Notice: orientation of I is None. And if you use description = describer.describe(condensed_structure), you will get this error.

To avoid it, a simple method is
describer = StructureDescriber(describe_component_makeup=False)

Or you can dive into the source code describer.py, and change the code from line 240 to 249:
if component_group.dimensionality in [1, 2]:
orientations = list(
{c.orientation for c in component_group.components}
)
s_direction = en.plural("direction", len(orientations))
# comp_desc += " oriented in the {} {}".format(
# en.join(orientations), s_direction
# )
comp_desc += f" oriented in the {orientations} {s_direction}"

@utf
Copy link
Member

utf commented Apr 25, 2024

Thanks for raising this. It has been fixed in the most recent version.

@utf utf closed this as completed Apr 25, 2024
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

5 participants