vibe-sketcherDocumentation

vibesketcher.document.periodic_measure

Minimum-image measurements between the sites of a periodic structure (#189).

Distances, angles, torsions and least-squares planes are measured between stored sites, each in a stated periodic image or, where none is stated, in the image nearest the atom before it in the list (for a plane, nearest the first atom). The first atom sits in its stored cell unless an image is given. Images are integer cell translations of the stored fractional coordinates, as in the bond graph: the position of site s in image I is (f_s + I) @ lattice. Only periodic axes take a nonzero image.

The nearest image is found by a complete, bounded search. With a first candidate at length d0 (the rounded fractional difference), any image at length d <= d0 has fractional components t_k = r . b_k bounded by d0 |b_k|, b_k the rows of the reciprocal basis (a_i . b_j = delta_ij). Every integer image in those ranges is tried, so skewed and triclinic cells are measured correctly; a cell needing more than MAX_IMAGES candidates is refused (reduce it first, for example to its Niggli cell). Images within TIE of the shortest are reported as ties; the lexicographically smallest is used.

Conventions:

  • The torsion A-B-C-D follows IUPAC (Moss, Pure Appl. Chem. 68, 2193 (1996), doi:10.1351/pac199668122193): positive when, looking along B->C, the bond to A turns clockwise onto the bond to D; in (-180, 180]. It is computed as atan2(|b2| b1 . (b2 x b3), (b1 x b2) . (b2 x b3)) (Blondel and Karplus, J. Comput. Chem. 17, 1132 (1996), doi:10.1002/(SICI)1096-987X(19960715)17:9<1132::AID-JCC5>3.0.CO;2-T), which stays accurate near 0 and 180 degrees.

  • The plane is the orthogonal least-squares plane of the atoms (Schomaker, Waser, Marsh and Bergman, Acta Cryst. 12, 600 (1959), doi:10.1107/S0365110X59001724): through the centroid, normal along the right singular vector of the centred positions with the smallest singular value. The residuals are the signed distances of the atoms from it; the rms is the smallest singular value over sqrt(n).

Measurements are read-only and never change the structure.

Functions

measure(structure, measurement)

One measurement: its value, the atoms in their images and the formula's terms.

measure_all(structure, measurements)

Every measurement, in order, with the conventions they use.

nearest_image(structure, origin, site, *[, ...])

The image of site nearest the Cartesian point origin: image, length, ties.

parse_measurement(text)

"torsion: A B C@0,0,1 D" as the fields of a Measurement.

resolve(structure, measurement)

Each atom with its image, Cartesian position and how the image was chosen.

Classes

Measurement(*, kind, atoms)

What to measure: a distance (2 atoms), angle (3), torsion (4) or plane (3 to 24).

SiteRef(*, site[, image])

A site in one periodic image; with no image, the nearest one (see the module).

class vibesketcher.document.periodic_measure.Measurement(*, kind, atoms)

Bases: BaseModel

What to measure: a distance (2 atoms), angle (3), torsion (4) or plane (3 to 24).

Also accepted as text, "angle: O1 Si1 O2@1,0,0": the kind (d and dihedral are aliases), then site IDs separated by spaces, each with an optional @n1,n2,n3 image.

Parameters:
  • kind (Literal['distance', 'angle', 'torsion', 'plane'])

  • atoms (Annotated[list[SiteRef], MinLen(min_length=1), MaxLen(max_length=24)])

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

kind: Kind
atoms: list[SiteRef]
class vibesketcher.document.periodic_measure.SiteRef(*, site, image=None)

Bases: BaseModel

A site in one periodic image; with no image, the nearest one (see the module).

Parameters:
  • site (Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=None, pattern=^[A-Za-z][A-Za-z0-9_-]{0,63}$, ascii_only=None)])

  • image (tuple[int, int, int] | None)

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

site: Annotated[str, StringConstraints(pattern=f'^{_SITE}$')]
image: tuple[int, int, int] | None
vibesketcher.document.periodic_measure.measure(structure, measurement)

One measurement: its value, the atoms in their images and the formula’s terms.

Parameters:
Return type:

dict[str, Any]

vibesketcher.document.periodic_measure.measure_all(structure, measurements)

Every measurement, in order, with the conventions they use.

Parameters:
Return type:

dict[str, Any]

vibesketcher.document.periodic_measure.nearest_image(structure, origin, site, *, exclude=None)

The image of site nearest the Cartesian point origin: image, length, ties.

exclude skips one image (the same atom, when a site is measured to its own images). The search is complete for any cell (module docstring).

Parameters:
Return type:

tuple[tuple[int, int, int], float, int]

vibesketcher.document.periodic_measure.parse_measurement(text)

"torsion: A B C@0,0,1 D" as the fields of a Measurement.

Parameters:

text (str)

Return type:

dict[str, Any]

vibesketcher.document.periodic_measure.resolve(structure, measurement)

Each atom with its image, Cartesian position and how the image was chosen.

Parameters:
Return type:

list[dict[str, Any]]