Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Convert XYZ data to bond lengths & angles, calculate contacts, planes and dihedral angles and print tables

License

NotificationsYou must be signed in to change notification settings

radi0sus/xyz2tab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

A Python 3 script for printing tables of bond lengths and (dihedral) angles from xyz files to the console. The script furthermore calculates average values, including a variety of statistical parameters, and is able to group bonding parameters. Two best-fit planes through selected or all atoms can be defined and atomic distances and angles between the planes can be calculated. Selected atoms or elements can be excluded from bond or angle tables. Contacts of two or more atoms can be included. The output should result in nicely rendered mark down tables. Molecules (atomic positions & bonds) and planes can be visualized.

asa

External modules

pandas (ver. <= 1.5.3 & => 2.1.1),numpy,scipy,tabulate,matplotlib

not compatible withpandas 2.1.0

Quick start

Start the script with:

python3 xyz2tab.py filename.xyz

to open the XYZ. It gives the following output:

Tables with general information. Please note that the covalent radius (columnCov. radius) has been increased byCovalent radius + = 8 % and bonds have been calculated by the sum of the radii given in the columnCov. radius +.

-------------------  ------------Filename          :  asa.xyzNumber of atoms   :  21Sum formula       :  C₉H₈O₄Formula weight    :  180.16 g/molExcluded atoms    :  NoneExcluded elements :  NoneIncluded contacts :  NoneCovalent radius + :  8.00 %-------------------  ------------| Element   |   Atom count |   Mass fraction /% |   Cov. radius /Å |   Cov. radius + /Å ||-----------|--------------|--------------------|------------------|--------------------|| C         |            9 |              60.00 |             0.76 |               0.82 || H         |            8 |               4.48 |             0.31 |               0.33 || O         |            4 |              35.52 |             0.66 |               0.71 |

A table of bond lengths. Please note that the number after the element indicates the position in the xyz file. The numbering starts with zero due toORCA conventions. This can be changed with the-i option (numberings starts with one).

| Atoms   |   Bond length /Å ||---------|------------------|| C0–C2   |           1.3983 || C0–C5   |           1.4051 || ...     | ....             |

A table with summarized general bond lengths.

| Atoms   | Bond lengths /Å   ||---------|-------------------|| C–C     | 1.3933 - 1.4993   || C–H     | 1.0865 - 1.0945   || C–O     | 1.2189 - 1.3969   || O–H     | 0.9806            |

A table with statistical parameters.

| Atoms   |   Count |   Mean /Å |   Median /Å |   Sam. std. dev. |   Pop. std. dev. |   Std. error |   Skewness ||---------|---------|-----------|-------------|------------------|------------------|--------------|------------|| C–C     |       8 |    1.4221 |      1.4009 |           0.0436 |           0.0408 |       0.0154 |     1.4385 || C–H     |       7 |    1.09   |      1.0893 |           0.0032 |           0.003  |       0.0012 |     0.289  || C–O     |       5 |    1.3147 |      1.3438 |           0.0876 |           0.0783 |       0.0392 |    -0.3848 || O–H     |       1 |    0.9806 |      0.9806 |         nan      |           0      |     nan      |   nan      |

Three tables with angles in a likewise manner.

Start the script with:

python3 xyz2tab.py filename.xyz > filename.md

will save the output in markdown format.

Convert markdown to docx (installPANDOC first):

pandoc filename.md -o filename.docx

This will convert the markdown file to a docx file. Open it with your favoriteword processor. Convert the file to even more formats such as HTML, PDF or TeX with PANDOC.

Command-line options

  • filename , required: filename, e.g.my_xyz.xyz, first two lines will be ignored, file format must beelement x y z, cartesian coordinates, units in Å
  • -eaatom(s), optional: exclude atoms, e.g.-ea H18 exclude bonds to H18,-ea H18 H19 exclude bonds to H18 and H19
  • -eeelements(s), optional: exclude elements, e.g.-ee H exclude bonds to hydrogen atoms,-ea H O exclude bonds to hydrogen and oxygen atoms
  • -sa, optional: sort values for bond lengths and angles ascending
  • -sd, optional: sort values for bond lengths and angles descending
  • -sae, optional: ascending alphabetical sort of elements
  • -sde, optional: descending alphabetical sort of elements
  • -icatoms, optional: include contacts of named atoms, e.g.-ic O10 O11, include the distance O10-O11, also include the angles X-O10-O11 and X-O11-O10. Input of more than two atoms is possible, e.g.-ic O10 O11 O12
  • -datom1 atom2 atom3 atom4, optional: calculate the dihedral angle of the selected atoms, e.g.-d C1 C2 O3 N4, calculates the dihedral angle C1-C2-O3-N4
  • -p1atom(s) oratom(s) : atom(s) oratom(s) : or: atom(s) or:, optional: calculate the best-fit plane through selected or all (:) atoms and prints the distance of the selected or all (:) for all atoms to the plane, e.g. an xyz-file containing 5 atoms:
    • -p1 C0 C1 O2 N3 N4, calculates the best-fit plane through C0 C1 O2 N3 and N4 and prints the distances
    • -p1 C0 : N4, calculates the best-fit plane through C0 C1 O2 N3 and N4 and prints the distances
    • -p1 : N4, calculates the best-fit plane through C0 C1 O2 N3 and N4 and prints the distances
    • -p1 C0 :, calculates the best-fit plane through C0 C1 O2 N3 and N4 and prints the distances
    • -p1 :, calculates the best-fit plane through C0 C1 O2 N3 and N4 and prints the distances
    • -p1 C0 : O2 N4, calculates the best-fit plane through C0 C1 O2 and N4 and prints the distances
  • -p2atom(s) oratom(s) : atom(s) oratom(s) : or: atom(s) or:, optional: calculate the best-fit plane through selected atoms and prints the distance of the selected or atoms to the plane and to the first plane 1 and prints the angle between plane 1 and 2, e.g.-p1 C0 : N4-p2 C11 : N15, calculates the best-fit planes through C0 C1 O2 N3 N4 and C11 C12 O13 N14 N15 and prints the distances and the interplanar angle.
  • -rN, optional: increase the covalent radii byN %, e.g.-r 20.1, increase the covalent radii by 20.1 %. The defaultN is8 %. The covalent radii used for the calculation of the bond length (bond length of A-B = rA + rB) is given in the last column of the summary table (Cov. radius +).
  • -s, optional: displays the molecule (atoms & bonds) and planes (if defined). Plane 1 is blue, plane 2 is red colored. Only bonds that have been calculated by the script are shown.
  • -sb, optional: same as-s with labeled bonds.
  • -sn, optional: same as-s with no atom labels.
  • -so, optional: show the orientation of the molecule with respect to the origin (x = 0 , y = 0, z = 0) and the xyz-axes of the cartesian coordinate system. The-so option can only be given in addition to-s,-sb or-sn and has no effect otherwise.
  • -v, optional: include two more tables (tables with general bond lengths and angles)
  • -i, optional: atom index starts with one. The first atom is now atom 1, e.g. C1.

Statistics

Statistics are derived from the values of the bonding parameters.

Sam. std. dev. = Sample standard deviation, Pop. std. dev. = Population standard deviation, Std. error = Standard error or standard error of mean. Please refer to literature or Wikipedia for the meaning of these terms. The population standard deviation is probably the value you are looking for.

Remarks

  • Labels are in the formatElement + Position in xyz file, e.g.C11 is a carbon atom at position 11 in the xyz file. Counting starts with zero. With the option-i counting starts at one, e.g. the atomC11 from the previous example would beC12.
  • The format of the tabular output can be easily changed in the script using another formatting option of thetabulate module.
  • With the standard covalent radii, many potential bonds will not be considered. An 8% larger covalent radius includes almost all expected bonds. All C-C distances below 1.6 Å are considered as bonds, for example.
  • For extreme cases (like in Jahn-Teller distorted geometries), radii can be increased even more (-r option) or contacts can be defined (-ic option).
  • -r 0 uses the unaltered covalent radii.
  • -d,-p1,-p2 and-s ignore excluded atoms (-ea) or elements (-ee) and sorting (-s...).
  • Distances are in Å (Angstrom) and angles are in ° (Degree). Input coordinates are assumed to be in Å (Angstrom) as well.
  • -p1 : N11 considers all atoms from the first atom in the xyz file to N11 for plane 1.
  • -p1 N11 : considers all atoms from N11 to the last atom in the xyz file for plane 1.
  • -p1 C0 N11 : considers atom C0 and all atoms from N11 to the last atom in the xyz file for plane 1.
  • -p1 C0 : C4 N11 : considers all atoms from C0 to C4 and all atoms from N11 to the last atom in the xyz file for plane 1.
  • To print more plane related parameters, remove the appropriate comments in the plane(s) section of the script.
  • If the-s option is invoked, the molecule and calculated planes will be shown. Plane 1 is blue colored and plane 2 red. It gives a quick overview over the atomic numbering / labeling and the positions of the planes. One can also check whether all bonds have been calculated or considered and adjust bonding with the-r or-ic options in case.

Known Issues

  • The script makes extensive use of Unicode characters, which can cause problems with output or conversion.
  • Verbose output (-v option) can be very large and confusing (looks nicer after formatting).
  • When rotating the molecule in the matplotlib window, planes are sometimes misplaced.
  • XYZ files containing more than one molecule are not supported. However, if the two header lines between different molecules are removed, the script reads the xyz file as a whole.

Examples

Example 1:

python3 xyz2tab.py formaldehyde.xyz

Openformaldehyde.xyz and show tables... Several options are shown.

show

Example 2:

python3 xyz2tab.py asa.xyz -ee H -s

Openasa.xyz, exclude bonds to hydrogen atoms (-ee H), show tables and the molecule (-s).Remark: The visualization always shows all atoms,-ee or-ea options are ignored. Included contacts (-ic option) are shown.

asa

-------------------  ------------Filename          :  asa.xyzNumber of atoms   :  21Sum formula       :  C₉H₈O₄Formula weight    :  180.16 g/molExcluded atoms    :  NoneExcluded elements :  HIncluded contacts :  NoneCovalent radius + :  8.00 %-------------------  ------------
ElementAtom countMass fraction /%Cov. radius /ÅCov. radius + /Å
C960.000.760.82
H84.480.310.33
O435.520.660.71
AtomsBond length /Å
C0–C21.3983
C0–C51.4051
......

...

AtomsBond lengths /Å
C–C1.3933 - 1.4993
C–O1.2189 - 1.3969
AtomsCountMean /ÅMedian /ÅSam. std. dev.Pop. std. dev.Std. errorSkewness
C–C81.42211.40090.04360.04080.01541.4385
C–O51.31471.34380.08760.07830.0392-0.3848
AtomsAngle /°
C2–C0–C5120.83
C3–C1–C6119.91
......

...

AtomsAngle /°
C–C–C116.52 - 125.18
C–C–O108.76 - 125.02
O–C–O120.00 / 126.89
C–O–C112.52
AtomsCountMean /°Median /°Sam. std. dev.Pop. std. dev.Std. errorSkewness
C–C–C8120.21119.992.482.320.880.82
C–C–O6118.68119.496.425.862.62-0.61
O–C–O2123.44123.444.883.453.45nan
C–O–C1112.52112.52nan0nannan

Example 3:

python3 xyz2tab.py asa.xyz -ee H -ic O11 O12 -sa -v -sb

Openasa.xyz, exclude bonds to hydrogen atoms (-ee H), include the contat O11 O12 (-ic O11 O12), sort values ascending (-sa), show verbose tables (-v) and the molecule with bond labels (-sb).Remark: The visualization always shows all atoms,-ee or-ea options are ignored. Included contacts (-ic option) are shown.

asa

...
AtomsBond length /Å
C7–O91.2189
C8–O101.2241
......
C4–C81.4993
O11–O122.6355
AtomsBond lengths /Å
C–O1.2189, 1.2241, 1.3438, 1.3900, 1.3969
C–C1.3933, 1.3936, 1.3983, 1.4006, 1.4013, 1.4051, 1.4850, 1.4993
O–O2.6355
AtomsBond lengths /Å
C–O1.2189 - 1.3969
C–C1.3933 - 1.4993
O–O2.6355

...

AtomsAngle /°
C6–O12–O1184.47
C8–O12–O1189.59
C7–O11–O1292.58
......

...

Example 4:

python3 xyz2tab.py asa.xyz -d C6 O12 C8 O10

Openasa.xyz and calculate the dihedral angle (-d) C6-O12-C8-O10.

...

Dihedral angle C6-O12-C8-O10: 2.85°

Example 5:

python3 xyz2tab.py asa.xyz -p1 C0 C1 C2 C3 C5 C6 C7 O9 O11 -p2 C4 C8 O10 O12 -s

is similar to:

python3 xyz2tab.py asa.xyz -p1 C0 : C3 C5 : C7 O9 O11 -p2 C4 C8 O10 O12 -s

Openasa.xyz and calculate the best-fit plane number one (-p1) through C0, C1, C2, C3, C4, C5, C6, C7, O9, O11 and the the best-fit plane number two (-p2) through C4, C8, O10, O12, print the distances and the angle between the planes and show the molecule and the planes (-s).

asa

...
Best-fit Plane 1 through 9 atoms.| Atom    |    Distance to Plane 1 /Å ||---------|---------------------------|| C0      |                   -0.0056 || C1      |                    0.0079 || C2      |                   -0.0204 || C3      |                   -0.0170 || C5      |                    0.0167 || C6      |                    0.0399 || C7      |                    0.0040 || O9      |                    0.0276 || O11     |                   -0.0532 |Best-fit Plane 2 through 4 atoms.| Atom    |    Distance to Plane 2 /Å |    Distance to Plane 1 /Å ||---------|---------------------------|---------------------------|| C4      |                   -0.0006 |                    1.2181 || C8      |                    0.0023 |                    1.3202 || O10     |                   -0.0009 |                    2.3736 || O12     |                   -0.0007 |                    0.0405 |Angle between Plane 1 and Plane 2: 93.69°

Example 6:

python3 xyz2tab.py h2o2.xyz -r 10 -d H2 O0 O1 H3 -p1 O0 O1 H2 -p2 O0 O1 H3 -s

Openh2o2.xyz, add +10% to radii (-r), calculate the dihedral angle (-d) H2-O0-O1-H3 and calculate the best-fit plane number one (-p1) through O0, O1, H3 and the best-fit plane number two (-p2) through O0, O1, H3, print the distances and the angle between the planes and show the molecule and the planes (-s).

h2o2

...
Dihedral angle H2-O0-O1-H3: 113.89°Best-fit Plane 1 through 3 atoms.| Atom    |    Distance to Plane 1 /Å ||---------|---------------------------|| O0      |                    0.0000 || O1      |                   -0.0000 || H2      |                    0.0000 |Best-fit Plane 2 through 3 atoms.| Atom    |    Distance to Plane 2 /Å |    Distance to Plane 1 /Å ||---------|---------------------------|---------------------------|| O0      |                   -0.0000 |                    0.0000 || O1      |                   -0.0000 |                   -0.0000 || H3      |                    0.0000 |                    0.8686 |Angle between Plane 1 and Plane 2: 113.89°

Example 7:

python3 xyz2tab.py nipor.xyz -sn -so

Opennipor.xyz, show the molecule with no labels (-sn) and show the orientation (-so).

nipor3

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp