├── requirements.txt ├── .gitignore ├── .DS_Store ├── tests ├── test.xyz ├── test.zmat ├── newsal.xyz ├── test-withvars.zmat ├── test_convert.xyz ├── test_vars.zmat ├── firstfive.xyz ├── tjthing.xyz ├── symmtest_convert.xyz ├── symmtest.zmat ├── tjthing.zmat ├── symmtest.xyz ├── bigtest_convert.xyz ├── firstfive_convert.xyz ├── salicin-A_convert.xyz ├── bigtest.xyz ├── salicin-A.xyz ├── bigtest.zmat └── salicin-A.zmat ├── LICENSE ├── README.md ├── gc.py └── gcutil.py /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | scipy -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *~ 3 | **/*.pyc 4 | **/*~ -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robashaw/geomConvert/HEAD/.DS_Store -------------------------------------------------------------------------------- /tests/test.xyz: -------------------------------------------------------------------------------- 1 | 4 2 | Blah 3 | H 0.0 1.6 2.5 4 | N 1.4 2.6 3.6 5 | O 2.3 3.0 4.1 6 | C 3.9 4.2 5.0 -------------------------------------------------------------------------------- /tests/test.zmat: -------------------------------------------------------------------------------- 1 | H 2 | N 1 2.04206 3 | O 1 3.13209 2 4.04249 4 | C 1 5.31225 2 4.79218 3 -43.60226 5 | -------------------------------------------------------------------------------- /tests/newsal.xyz: -------------------------------------------------------------------------------- 1 | 3 2 | INSERT TITLE CARD HERE 3 | O 0.00000 0.00000 0.00000 4 | O 0.00000 0.00000 2.27914 5 | O 0.00000 3.55653 2.07097 6 | -------------------------------------------------------------------------------- /tests/test-withvars.zmat: -------------------------------------------------------------------------------- 1 | H 2 | N 1 r1 3 | O 1 3.13209 2 a1 4 | C 1 r2 2 4.79218 3 d1 5 | 6 | r1=2.04206 7 | a1=4.04249 8 | r2=5.31225 9 | d1=-43.60226 10 | -------------------------------------------------------------------------------- /tests/test_convert.xyz: -------------------------------------------------------------------------------- 1 | 4 2 | INSERT TITLE CARD HERE 3 | H 0.00000 0.00000 0.00000 4 | N 2.04206 0.00000 0.00000 5 | O 3.12430 0.22080 0.00000 6 | C 5.29368 0.32137 0.30606 7 | -------------------------------------------------------------------------------- /tests/test_vars.zmat: -------------------------------------------------------------------------------- 1 | H 2 | N 1 R1 3 | O 1 R2 2 A1 4 | C 1 R3 2 A2 3 D1 5 | 6 | R1 = 2.04206 7 | R2 = 3.13209 8 | R3 = 5.31225 9 | 10 | A1 = 168.46867 11 | A2 = 172.22804 12 | 13 | D1 = 42.40474 14 | -------------------------------------------------------------------------------- /tests/firstfive.xyz: -------------------------------------------------------------------------------- 1 | 5 2 | Energy: -647987.8770234 3 | O -1.04480 0.92441 0.54698 4 | O 0.90700 -0.24205 0.70289 5 | O -3.17079 -2.51063 -0.23949 6 | O -4.35892 0.02068 -0.62097 7 | O -0.32867 -2.51468 -0.43442 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/tjthing.xyz: -------------------------------------------------------------------------------- 1 | 8 2 | INSERT TITLE CARD HERE 3 | Cu 0.00000 0.00000 0.00000 4 | O 1.79703 0.00000 0.00000 5 | O -2.69927 0.14194 0.00000 6 | H -3.23806 -0.24266 -0.69526 7 | C 2.54661 1.11240 0.49557 8 | H 2.83373 1.74126 -0.32113 9 | H 3.42243 0.75723 0.99727 10 | H 1.94456 1.67106 1.18137 11 | -------------------------------------------------------------------------------- /tests/symmtest_convert.xyz: -------------------------------------------------------------------------------- 1 | 10 2 | INSERT TITLE CARD HERE 3 | C 0.00000 0.00000 0.00000 4 | O 1.21361 0.00000 0.00000 5 | H -0.63755 0.90233 0.00000 6 | O -0.78131 -1.11342 0.00000 7 | H -0.21591 -1.92209 0.00000 8 | O -0.49175 -3.82892 0.00000 9 | C -1.68072 -4.12031 0.00000 10 | H -2.05839 -5.15643 0.00000 11 | O -2.70690 -3.25056 0.00000 12 | H -2.33812 -2.34194 0.00000 13 | -------------------------------------------------------------------------------- /tests/symmtest.zmat: -------------------------------------------------------------------------------- 1 | C 2 | O 1 1.21361 3 | H 1 1.10484 2 125.24316 4 | O 1 1.36020 2 125.05832 3 -180.00000 5 | H 2 2.39540 3 79.34732 4 0.00000 6 | O 3 4.73350 4 5.84451 5 0.00000 7 | C 4 3.13853 5 51.61319 6 0.00000 8 | H 5 3.72233 6 21.43704 7 0.00000 9 | O 6 2.28940 7 28.40343 8 -180.00000 10 | H 7 1.89599 8 139.68597 9 0.00000 11 | -------------------------------------------------------------------------------- /tests/tjthing.zmat: -------------------------------------------------------------------------------- 1 | Cu 2 | O 1 rCuO 3 | O 1 rOCu 2 aOCuO 4 | H 3 rHO 2 aHOO 1 dHOOCu 5 | C 2 rCO 3 aCOO 4 dCOOH 6 | H 5 rH1C 2 aH1CO 1 dH1COCu 7 | H 5 rH2C 2 aH2CO 1 dH2COCu 8 | H 5 rH3C 2 aH2CO 1 dH3COCu 9 | 10 | rCuO=1.79703 11 | rOCu=2.703 12 | rHO=0.96000 13 | rCO=1.43000 14 | rH1C=1.07 15 | rH2C=1.07 16 | rH3C=1.07 17 | 18 | aOCuO=176.99 19 | aHOO=123.252 20 | aCOO=119.959 21 | aH1CO=109.471 22 | aH2CO=109.471 23 | aH3CO=109.471 24 | 25 | dHOOCu=-60.000 26 | dCOOH=143.578 27 | dH1COCu=-96.695 28 | dH2COCu=143.305 29 | dH3COCu=23.305 30 | -------------------------------------------------------------------------------- /tests/symmtest.xyz: -------------------------------------------------------------------------------- 1 | 10 2 | MP2/AVDZ,H=VDZ ENERGY=-378.66215003 3 | C 0.0000000000 -0.4698122952 2.1391233286 4 | O 0.0000000000 0.5523090776 2.7934304269 5 | H 0.0000000000 -1.4932504125 2.5553573324 6 | O 0.0000000000 -0.5275574540 0.7801527391 7 | H 0.0000000000 0.3846241118 0.4039088689 8 | O 0.0000000000 1.1803585191 -1.3507763628 9 | C 0.0000000000 0.3360820239 -2.2372151381 10 | H 0.0000000000 0.5766355527 -3.3134640678 11 | O 0.0000000000 -0.9970911345 -2.0579402982 12 | H 0.0000000000 -1.1763897412 -1.0938887614 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Robert Shaw 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # geomconvert 2 | A python utility to convert between Cartesian and Z-matrix geometries. 3 | 4 | RECENTLY ADDED: when converting from zmat to xyz, variables can now be read with no caveats. 5 | 6 | Running the below will print the output to the standard output stream (i.e. the terminal in most cases); this can be piped into a file in the usual way, e.g. 7 | 8 | python3 gc.py -xyz test.xyz > test.zmat 9 | 10 | ## Usage 11 | 12 | To convert from XYZ to Z-matrix: 13 | 14 | python3 gc.py -xyz test.xyz 15 | 16 | for files in XYZ format, i.e. 17 | 18 | Number of atoms 19 | 20 | TITLE CARD 21 | 22 | Atom x y z 23 | 24 | Atom x y z 25 | 26 | ... 27 | 28 | The default is to print the values of distances/angles/dihedrals. These can instead be printed as variables with the options 29 | 30 | --rvar=True 31 | --avar=True 32 | --dvar=True 33 | 34 | respectively. Alternative 35 | 36 | --allvar=True 37 | 38 | will set all the above to true. 39 | 40 | To convert from Z-matrix to XYZ: 41 | 42 | python gc.py -zmat test.zmat 43 | 44 | for files containing a Z-matrix. This no longer assumes that the Z-matrix has values not variables for distances/angles/dihedrals, and can read variables with no additional options. 45 | 46 | 47 | -------------------------------------------------------------------------------- /tests/bigtest_convert.xyz: -------------------------------------------------------------------------------- 1 | 38 2 | INSERT TITLE CARD HERE 3 | O 0.00000 0.00000 0.00000 4 | O 2.27914 0.00000 0.00000 5 | O -0.11640 4.11391 0.00000 6 | O -2.45550 2.62107 0.51449 7 | O 2.30627 2.75436 0.63084 8 | O -2.21022 -1.59073 0.29927 9 | O 4.79287 1.34447 0.56634 10 | C -0.04548 2.79485 0.49850 11 | C -1.27275 2.05301 0.00126 12 | C 1.21657 2.08391 0.05231 13 | C -1.21096 0.59991 0.46093 14 | C 1.14684 0.63392 0.50972 15 | C -2.33857 -0.24445 -0.09964 16 | C 2.85505 -0.99645 0.74019 17 | C 4.25364 -1.02795 0.72861 18 | C 2.11543 -1.93298 1.45021 19 | C 4.89927 -2.03599 1.43614 20 | C 5.00235 0.05241 -0.00716 21 | C 2.78601 -2.92528 2.16200 22 | C 4.17392 -2.98602 2.15211 23 | H -0.06554 2.81044 1.59892 24 | H -1.27436 2.08083 -1.09837 25 | H 1.27579 2.08771 -1.04503 26 | H -1.24214 0.56305 1.55972 27 | H 1.15140 0.58093 1.60972 28 | H -2.34022 -0.15564 -1.19380 29 | H -3.29092 0.12121 0.28116 30 | H 0.69309 4.57488 0.25107 31 | H -2.41789 3.57240 0.35649 32 | H 3.13821 2.29159 0.42496 33 | H -1.36899 -1.91589 -0.04120 34 | H 1.03190 -1.89091 1.43271 35 | H 5.98466 -2.07333 1.43127 36 | H 6.07175 -0.17865 -0.02693 37 | H 4.65300 0.13996 -1.03539 38 | H 2.21367 -3.65939 2.71759 39 | H 4.69030 -3.76501 2.70023 40 | H 5.06583 1.32786 1.49002 41 | -------------------------------------------------------------------------------- /tests/firstfive_convert.xyz: -------------------------------------------------------------------------------- 1 | 5 2 | INSERT TITLE CARD HERE 3 | O 0.00000 0.00000 0.00000 4 | O 2.27914 0.00000 0.00000 5 | O -0.11640 4.11391 0.00000 6 | O -2.45550 2.62107 0.51449 7 | O 2.30627 2.75436 0.63084 8 | O -2.21022 -1.59073 0.29927 9 | O 4.79287 1.34447 0.56634 10 | C -0.04548 2.79485 0.49850 11 | C -1.27275 2.05301 0.00126 12 | C 1.21657 2.08391 0.05231 13 | C -1.21096 0.59991 0.46093 14 | C 1.14684 0.63392 0.50972 15 | C -2.33857 -0.24445 -0.09964 16 | C 2.85505 -0.99645 0.74019 17 | C 4.25364 -1.02795 0.72861 18 | C 2.11543 -1.93298 1.45021 19 | C 4.89927 -2.03599 1.43614 20 | C 5.00235 0.05241 -0.00716 21 | C 2.78601 -2.92528 2.16200 22 | C 4.17392 -2.98602 2.15211 23 | H -0.06554 2.81044 1.59892 24 | H -1.27436 2.08083 -1.09837 25 | H 1.27579 2.08771 -1.04503 26 | H -1.24214 0.56305 1.55972 27 | H 1.15140 0.58093 1.60972 28 | H -2.34022 -0.15564 -1.19380 29 | H -3.29092 0.12121 0.28116 30 | H 0.69309 4.57488 0.25107 31 | H -2.41789 3.57240 0.35649 32 | H 3.13821 2.29159 0.42496 33 | H -1.36899 -1.91589 -0.04120 34 | H 1.03190 -1.89091 1.43271 35 | H 5.98466 -2.07333 1.43127 36 | H 6.07175 -0.17865 -0.02693 37 | H 4.65300 0.13996 -1.03539 38 | H 2.21367 -3.65939 2.71759 39 | H 4.69030 -3.76501 2.70023 40 | H 5.06583 1.32786 1.49002 41 | -------------------------------------------------------------------------------- /tests/salicin-A_convert.xyz: -------------------------------------------------------------------------------- 1 | 38 2 | INSERT TITLE CARD HERE 3 | O 0.00000 0.00000 0.00000 4 | O 2.27914 0.00000 0.00000 5 | O -0.11640 4.11391 0.00000 6 | O -2.45550 2.62107 0.51449 7 | O 2.30627 2.75436 0.63084 8 | O -2.21022 -1.59073 0.29927 9 | O 4.79287 1.34447 0.56634 10 | C -0.04548 2.79485 0.49850 11 | C -1.27275 2.05301 0.00126 12 | C 1.21657 2.08391 0.05231 13 | C -1.21096 0.59991 0.46093 14 | C 1.14684 0.63392 0.50972 15 | C -2.33857 -0.24445 -0.09964 16 | C 2.85505 -0.99645 0.74019 17 | C 4.25364 -1.02795 0.72861 18 | C 2.11543 -1.93298 1.45021 19 | C 4.89927 -2.03599 1.43614 20 | C 5.00235 0.05241 -0.00716 21 | C 2.78601 -2.92528 2.16200 22 | C 4.17392 -2.98602 2.15211 23 | H -0.06554 2.81044 1.59892 24 | H -1.27436 2.08083 -1.09837 25 | H 1.27579 2.08771 -1.04503 26 | H -1.24214 0.56305 1.55972 27 | H 1.15140 0.58093 1.60972 28 | H -2.34022 -0.15564 -1.19380 29 | H -3.29092 0.12121 0.28116 30 | H 0.69309 4.57488 0.25107 31 | H -2.41789 3.57240 0.35649 32 | H 3.13821 2.29159 0.42496 33 | H -1.36899 -1.91589 -0.04120 34 | H 1.03190 -1.89091 1.43271 35 | H 5.98466 -2.07333 1.43127 36 | H 6.07175 -0.17865 -0.02693 37 | H 4.65300 0.13996 -1.03539 38 | H 2.21367 -3.65939 2.71759 39 | H 4.69030 -3.76501 2.70023 40 | H 5.06583 1.32786 1.49002 41 | -------------------------------------------------------------------------------- /tests/bigtest.xyz: -------------------------------------------------------------------------------- 1 | 38 2 | Energy: -647987.8770234 3 | O -1.04480 0.92441 0.54698 4 | O 0.90700 -0.24205 0.70289 5 | O -3.17079 -2.51063 -0.23949 6 | O -4.35892 0.02068 -0.62097 7 | O -0.32867 -2.51468 -0.43442 8 | O -2.10769 3.44528 0.40366 9 | O 2.48525 -2.59795 0.06567 10 | C -2.38311 -1.36244 -0.47333 11 | C -3.14577 -0.16798 0.07017 12 | C -1.02128 -1.46171 0.18461 13 | C -2.30590 1.09374 -0.10089 14 | C -0.29592 -0.13560 0.00617 15 | C -2.94253 2.31615 0.53086 16 | C 2.00571 0.40466 0.20579 17 | C 3.21715 -0.28586 0.31876 18 | C 1.94362 1.66989 -0.36308 19 | C 4.37620 0.33081 -0.13937 20 | C 3.21218 -1.68123 0.88625 21 | C 3.11695 2.26098 -0.82665 22 | C 4.33391 1.60097 -0.71053 23 | H -2.23743 -1.22416 -1.55557 24 | H -3.33125 -0.33194 1.14192 25 | H -1.14248 -1.63610 1.26282 26 | H -2.14417 1.28206 -1.17238 27 | H -0.09546 0.04828 -1.06101 28 | H -3.15724 2.10112 1.58570 29 | H -3.87919 2.54184 0.02348 30 | H -2.66570 -3.28425 -0.51729 31 | H -4.81976 -0.82696 -0.64366 32 | H 0.57982 -2.57378 -0.08828 33 | H -1.27988 3.24726 0.85622 34 | H 0.99229 2.18646 -0.42803 35 | H 5.32334 -0.19359 -0.05329 36 | H 4.23873 -2.03480 1.02250 37 | H 2.71054 -1.70879 1.85298 38 | H 3.07450 3.24881 -1.27112 39 | H 5.24474 2.06877 -1.06469 40 | H 2.87033 -2.60497 -0.81733 41 | -------------------------------------------------------------------------------- /tests/salicin-A.xyz: -------------------------------------------------------------------------------- 1 | 38 2 | Energy: -647987.8770234 3 | O -1.04480 0.92441 0.54698 4 | O 0.90700 -0.24205 0.70289 5 | O -3.17079 -2.51063 -0.23949 6 | O -4.35892 0.02068 -0.62097 7 | O -0.32867 -2.51468 -0.43442 8 | O -2.10769 3.44528 0.40366 9 | O 2.48525 -2.59795 0.06567 10 | C -2.38311 -1.36244 -0.47333 11 | C -3.14577 -0.16798 0.07017 12 | C -1.02128 -1.46171 0.18461 13 | C -2.30590 1.09374 -0.10089 14 | C -0.29592 -0.13560 0.00617 15 | C -2.94253 2.31615 0.53086 16 | C 2.00571 0.40466 0.20579 17 | C 3.21715 -0.28586 0.31876 18 | C 1.94362 1.66989 -0.36308 19 | C 4.37620 0.33081 -0.13937 20 | C 3.21218 -1.68123 0.88625 21 | C 3.11695 2.26098 -0.82665 22 | C 4.33391 1.60097 -0.71053 23 | H -2.23743 -1.22416 -1.55557 24 | H -3.33125 -0.33194 1.14192 25 | H -1.14248 -1.63610 1.26282 26 | H -2.14417 1.28206 -1.17238 27 | H -0.09546 0.04828 -1.06101 28 | H -3.15724 2.10112 1.58570 29 | H -3.87919 2.54184 0.02348 30 | H -2.66570 -3.28425 -0.51729 31 | H -4.81976 -0.82696 -0.64366 32 | H 0.57982 -2.57378 -0.08828 33 | H -1.27988 3.24726 0.85622 34 | H 0.99229 2.18646 -0.42803 35 | H 5.32334 -0.19359 -0.05329 36 | H 4.23873 -2.03480 1.02250 37 | H 2.71054 -1.70879 1.85298 38 | H 3.07450 3.24881 -1.27112 39 | H 5.24474 2.06877 -1.06469 40 | H 2.87033 -2.60497 -0.81733 41 | -------------------------------------------------------------------------------- /tests/bigtest.zmat: -------------------------------------------------------------------------------- 1 | O 2 | O 1 2.27914 3 | O 1 4.11556 2 91.62069 4 | O 1 3.62825 2 132.59200 3 -11.10547 5 | O 2 2.82581 3 33.12439 4 -145.37523 6 | O 3 6.08413 4 37.79770 5 28.38776 7 | O 4 7.36012 5 11.63314 6 -1.83794 8 | C 5 2.35582 6 44.80851 7 176.23242 9 | C 6 3.77419 7 53.19294 8 8.41900 10 | C 7 3.68795 8 8.79354 9 31.09637 11 | C 8 2.48546 9 35.33977 10 -54.91321 12 | C 9 2.85075 10 32.22158 11 0.06971 13 | C 10 4.25245 11 10.37418 12 95.72068 14 | C 11 4.37708 12 22.37699 13 39.69863 15 | C 12 3.53015 13 137.58922 14 5.78433 16 | C 13 5.00912 14 15.08618 15 163.84875 17 | C 14 2.39663 15 30.67477 16 -0.78381 18 | C 15 1.50636 16 148.10520 17 -176.01152 19 | C 16 1.39319 17 59.68542 18 -178.11788 20 | C 17 1.39331 18 150.86804 19 -1.59340 21 | H 18 5.98913 19 75.37044 20 -151.78682 22 | H 19 7.22342 20 126.06101 21 28.34189 23 | H 20 6.66060 21 25.04034 22 41.14787 24 | H 21 2.53706 22 65.78805 23 -110.88982 25 | H 22 3.93291 23 50.94845 24 0.18558 26 | H 23 4.25797 24 43.51145 25 137.93548 27 | H 24 2.45508 25 147.83541 26 4.45931 28 | H 25 4.24353 26 82.63847 27 -92.63051 29 | H 26 4.03828 27 61.77777 28 -22.53712 30 | H 27 6.78711 28 29.56833 29 -173.86683 31 | H 28 6.81672 29 54.67015 30 8.75230 32 | H 29 6.55035 30 45.37417 31 17.40045 33 | H 30 5.30731 31 81.11855 32 27.72649 34 | H 31 7.64087 32 33.60619 33 -28.26627 35 | H 32 4.82994 33 42.78711 34 11.20537 36 | H 33 4.28842 34 120.51278 35 -23.45794 37 | H 34 4.71251 35 103.40268 36 9.10877 38 | H 35 2.82121 36 76.17660 37 -76.03124 39 | -------------------------------------------------------------------------------- /tests/salicin-A.zmat: -------------------------------------------------------------------------------- 1 | O 2 | O 1 2.27914 3 | O 1 4.11556 2 91.62069 4 | O 1 3.62825 2 132.59200 3 -11.10547 5 | O 2 2.82581 3 33.12439 4 -145.37523 6 | O 3 6.08413 4 37.79770 5 28.38776 7 | O 4 7.36012 5 11.63314 6 -1.83794 8 | C 5 2.35582 6 44.80851 7 176.23242 9 | C 6 3.77419 7 53.19294 8 8.41900 10 | C 7 3.68795 8 8.79354 9 31.09637 11 | C 8 2.48546 9 35.33977 10 -54.91321 12 | C 9 2.85075 10 32.22158 11 0.06971 13 | C 10 4.25245 11 10.37418 12 95.72068 14 | C 11 4.37708 12 22.37699 13 39.69863 15 | C 12 3.53015 13 137.58922 14 5.78433 16 | C 13 5.00912 14 15.08618 15 163.84875 17 | C 14 2.39663 15 30.67477 16 -0.78381 18 | C 15 1.50636 16 148.10520 17 -176.01152 19 | C 16 1.39319 17 59.68542 18 -178.11788 20 | C 17 1.39331 18 150.86804 19 -1.59340 21 | H 18 5.98913 19 75.37044 20 -151.78682 22 | H 19 7.22342 20 126.06101 21 28.34189 23 | H 20 6.66060 21 25.04034 22 41.14787 24 | H 21 2.53706 22 65.78805 23 -110.88982 25 | H 22 3.93291 23 50.94845 24 0.18558 26 | H 23 4.25797 24 43.51145 25 137.93548 27 | H 24 2.45508 25 147.83541 26 4.45931 28 | H 25 4.24353 26 82.63847 27 -92.63051 29 | H 26 4.03828 27 61.77777 28 -22.53712 30 | H 27 6.78711 28 29.56833 29 -173.86683 31 | H 28 6.81672 29 54.67015 30 8.75230 32 | H 29 6.55035 30 45.37417 31 17.40045 33 | H 30 5.30731 31 81.11855 32 27.72649 34 | H 31 7.64087 32 33.60619 33 -28.26627 35 | H 32 4.82994 33 42.78711 34 11.20537 36 | H 33 4.28842 34 120.51278 35 -23.45794 37 | H 34 4.71251 35 103.40268 36 9.10877 38 | H 35 2.82121 36 76.17660 37 -76.03124 39 | -------------------------------------------------------------------------------- /gc.py: -------------------------------------------------------------------------------- 1 | # UTILITY TO CONVERT BETWEEN XYZ AND Z-MATRIX GEOMETRIES 2 | # Copyright 2017 Robert A Shaw 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining 5 | # a copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the Software 9 | # is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 20 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | # 22 | # Usage: python3 gc.py -xyz [file to convert] 23 | # or python3 gc.py -zmat [file to convert] 24 | # possible flags for zmatrix printing are: 25 | # --rvar/avar/dvar = True/False 26 | # --allvar = True/False (sets all above) 27 | 28 | import numpy as np 29 | import argparse 30 | import gcutil as gc 31 | 32 | parser = argparse.ArgumentParser() 33 | parser.add_argument("-xyz", dest="xyzfile", required=False, type=str, help="File containing xyz coordinates") 34 | parser.add_argument("-zmat", dest="zmatfile", required=False, type=str, help="File containing Z-matrix") 35 | parser.add_argument("--rvar", dest="rvar", required=False, type=bool, default=False, help="Print distances as variables") 36 | parser.add_argument("--avar", dest="avar", required=False, type=bool, default=False, help="Print angles as variables") 37 | parser.add_argument("--dvar", dest="dvar", required=False, type=bool, default=False, help="Print dihedrals as variables") 38 | parser.add_argument("--allvar", dest="allvar", required=False, type=bool, default=False, help="Print all values as variables") 39 | args = parser.parse_args() 40 | 41 | xyzfilename = args.xyzfile 42 | zmatfilename = args.zmatfile 43 | xyz = np.array 44 | rvar = args.rvar or args.allvar 45 | avar = args.avar or args.allvar 46 | dvar = args.dvar or args.allvar 47 | 48 | if (xyzfilename == None and zmatfilename == None): 49 | print("Please specify an input geometry") 50 | 51 | elif (zmatfilename == None): 52 | xyzarr, atomnames = gc.readxyz(xyzfilename) 53 | distmat = gc.distance_matrix(xyzarr) 54 | gc.write_zmat(xyzarr, distmat, atomnames, rvar=rvar, avar=avar, dvar=dvar) 55 | else: 56 | atomnames, rconnect, rlist, aconnect, alist, dconnect, dlist = gc.readzmat(zmatfilename) 57 | gc.write_xyz(atomnames, rconnect, rlist, aconnect, alist, dconnect, dlist) 58 | -------------------------------------------------------------------------------- /gcutil.py: -------------------------------------------------------------------------------- 1 | # UTILITY TO CONVERT BETWEEN XYZ AND Z-MATRIX GEOMETRIES 2 | # Copyright 2017 Robert A Shaw 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining 5 | # a copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the Software 9 | # is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 20 | # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | # Utilities for gc.py 22 | 23 | import numpy as np 24 | from scipy.spatial.distance import cdist 25 | 26 | def replace_vars(vlist, variables): 27 | """ Replaces a list of variable names (vlist) with their values 28 | from a dictionary (variables). 29 | """ 30 | for i, v in enumerate(vlist): 31 | if v in variables: 32 | vlist[i] = variables[v] 33 | else: 34 | try: 35 | # assume the "variable" is a number 36 | vlist[i] = float(v) 37 | except: 38 | print("Problem with entry " + str(v)) 39 | 40 | def readxyz(filename): 41 | """ Reads in a .xyz file in the standard format, 42 | returning xyz coordinates as a numpy array 43 | and a list of atom names. 44 | """ 45 | xyzf = open(filename, 'r') 46 | xyzarr = np.zeros([1, 3]) 47 | atomnames = [] 48 | if not xyzf.closed: 49 | # Read the first line to get the number of particles 50 | npart = int(xyzf.readline()) 51 | # and next for title card 52 | title = xyzf.readline() 53 | 54 | # Make an N x 3 matrix of coordinates 55 | xyzarr = np.zeros([npart, 3]) 56 | i = 0 57 | for line in xyzf: 58 | words = line.split() 59 | if (len(words) > 3): 60 | atomnames.append(words[0]) 61 | xyzarr[i][0] = float(words[1]) 62 | xyzarr[i][1] = float(words[2]) 63 | xyzarr[i][2] = float(words[3]) 64 | i = i + 1 65 | return (xyzarr, atomnames) 66 | 67 | def readzmat(filename): 68 | """ Reads in a z-matrix in standard format, 69 | returning a list of atoms and coordinates. 70 | """ 71 | zmatf = open(filename, 'r') 72 | atomnames = [] 73 | rconnect = [] # bond connectivity 74 | rlist = [] # list of bond length values 75 | aconnect = [] # angle connectivity 76 | alist = [] # list of bond angle values 77 | dconnect = [] # dihedral connectivity 78 | dlist = [] # list of dihedral values 79 | variables = {} # dictionary of named variables 80 | 81 | if not zmatf.closed: 82 | for line in zmatf: 83 | words = line.split() 84 | eqwords = line.split('=') 85 | 86 | if len(eqwords) > 1: 87 | # named variable found 88 | varname = str(eqwords[0]).strip() 89 | try: 90 | varval = float(eqwords[1]) 91 | variables[varname] = varval 92 | except: 93 | print("Invalid variable definition: " + line) 94 | 95 | else: 96 | # no variable, just a number 97 | # valid line has form 98 | # atomname index1 bond_length index2 bond_angle index3 dihedral 99 | if len(words) > 0: 100 | atomnames.append(words[0]) 101 | if len(words) > 1: 102 | rconnect.append(int(words[1])) 103 | if len(words) > 2: 104 | rlist.append(words[2]) 105 | if len(words) > 3: 106 | aconnect.append(int(words[3])) 107 | if len(words) > 4: 108 | alist.append(words[4]) 109 | if len(words) > 5: 110 | dconnect.append(int(words[5])) 111 | if len(words) > 6: 112 | dlist.append(words[6]) 113 | 114 | # replace named variables with their values 115 | replace_vars(rlist, variables) 116 | replace_vars(alist, variables) 117 | replace_vars(dlist, variables) 118 | 119 | return (atomnames, rconnect, rlist, aconnect, alist, dconnect, dlist) 120 | 121 | def distance_matrix(xyzarr): 122 | """Returns the pairwise distance matrix between atom 123 | from a set of xyz coordinates 124 | """ 125 | return cdist(xyzarr, xyzarr) 126 | 127 | def angle(xyzarr, i, j, k): 128 | """Return the bond angle in degrees between three atoms 129 | with indices i, j, k given a set of xyz coordinates. 130 | atom j is the central atom 131 | """ 132 | rij = xyzarr[i] - xyzarr[j] 133 | rkj = xyzarr[k] - xyzarr[j] 134 | cos_theta = np.dot(rij, rkj) 135 | sin_theta = np.linalg.norm(np.cross(rij, rkj)) 136 | theta = np.arctan2(sin_theta, cos_theta) 137 | theta = 180.0 * theta / np.pi 138 | return theta 139 | 140 | def dihedral(xyzarr, i, j, k, l): 141 | """Return the dihedral angle in degrees between four atoms 142 | with indices i, j, k, l given a set of xyz coordinates. 143 | connectivity is i->j->k->l 144 | """ 145 | rji = xyzarr[j] - xyzarr[i] 146 | rkj = xyzarr[k] - xyzarr[j] 147 | rlk = xyzarr[l] - xyzarr[k] 148 | v1 = np.cross(rji, rkj) 149 | v1 = v1 / np.linalg.norm(v1) 150 | v2 = np.cross(rlk, rkj) 151 | v2 = v2 / np.linalg.norm(v2) 152 | m1 = np.cross(v1, rkj) / np.linalg.norm(rkj) 153 | x = np.dot(v1, v2) 154 | y = np.dot(m1, v2) 155 | chi = np.arctan2(y, x) 156 | chi = -180.0 - 180.0 * chi / np.pi 157 | if (chi < -180.0): 158 | chi = chi + 360.0 159 | return chi 160 | 161 | def write_zmat(xyzarr, distmat, atomnames, rvar=False, avar=False, dvar=False): 162 | """Prints a z-matrix from xyz coordinates, distances, and atomnames, 163 | optionally with the coordinate values replaced with variables. 164 | """ 165 | npart, ncoord = xyzarr.shape 166 | rlist = [] # list of bond lengths 167 | alist = [] # list of bond angles (degrees) 168 | dlist = [] # list of dihedral angles (degrees) 169 | if npart > 0: 170 | # Write the first atom 171 | print(atomnames[0]) 172 | 173 | if npart > 1: 174 | # and the second, with distance from first 175 | n = atomnames[1] 176 | rlist.append(distmat[0][1]) 177 | if (rvar): 178 | r = 'R1' 179 | else: 180 | r = '{:>11.5f}'.format(rlist[0]) 181 | print('{:<3s} {:>4d} {:11s}'.format(n, 1, r)) 182 | 183 | if npart > 2: 184 | n = atomnames[2] 185 | 186 | rlist.append(distmat[0][2]) 187 | if (rvar): 188 | r = 'R2' 189 | else: 190 | r = '{:>11.5f}'.format(rlist[1]) 191 | 192 | alist.append(angle(xyzarr, 2, 0, 1)) 193 | if (avar): 194 | t = 'A1' 195 | else: 196 | t = '{:>11.5f}'.format(alist[0]) 197 | 198 | print('{:<3s} {:>4d} {:11s} {:>4d} {:11s}'.format(n, 1, r, 2, t)) 199 | 200 | if npart > 3: 201 | for i in range(3, npart): 202 | n = atomnames[i] 203 | 204 | rlist.append(distmat[i-3][i]) 205 | if (rvar): 206 | r = 'R{:<4d}'.format(i) 207 | else: 208 | r = '{:>11.5f}'.format(rlist[i-1]) 209 | 210 | alist.append(angle(xyzarr, i, i-3, i-2)) 211 | if (avar): 212 | t = 'A{:<4d}'.format(i-1) 213 | else: 214 | t = '{:>11.5f}'.format(alist[i-2]) 215 | 216 | dlist.append(dihedral(xyzarr, i, i-3, i-2, i-1)) 217 | if (dvar): 218 | d = 'D{:<4d}'.format(i-2) 219 | else: 220 | d = '{:>11.5f}'.format(dlist[i-3]) 221 | print('{:3s} {:>4d} {:11s} {:>4d} {:11s} {:>4d} {:11s}'.format(n, i-2, r, i-1, t, i, d)) 222 | if (rvar): 223 | print(" ") 224 | for i in range(npart-1): 225 | print('R{:<4d} = {:>11.5f}'.format(i+1, rlist[i])) 226 | if (avar): 227 | print(" ") 228 | for i in range(npart-2): 229 | print('A{:<4d} = {:>11.5f}'.format(i+1, alist[i])) 230 | if (dvar): 231 | print(" ") 232 | for i in range(npart-3): 233 | print('D{:<4d} = {:>11.5f}'.format(i+1, dlist[i])) 234 | 235 | def write_xyz(atomnames, rconnect, rlist, aconnect, alist, dconnect, dlist): 236 | """Prints out an xyz file from a decomposed z-matrix""" 237 | npart = len(atomnames) 238 | print(npart) 239 | print('INSERT TITLE CARD HERE') 240 | 241 | # put the first atom at the origin 242 | xyzarr = np.zeros([npart, 3]) 243 | if (npart > 1): 244 | # second atom at [r01, 0, 0] 245 | xyzarr[1] = [rlist[0], 0.0, 0.0] 246 | 247 | if (npart > 2): 248 | # third atom in the xy-plane 249 | # such that the angle a012 is correct 250 | i = rconnect[1] - 1 251 | j = aconnect[0] - 1 252 | r = rlist[1] 253 | theta = alist[0] * np.pi / 180.0 254 | x = r * np.cos(theta) 255 | y = r * np.sin(theta) 256 | a_i = xyzarr[i] 257 | b_ij = xyzarr[j] - xyzarr[i] 258 | if (b_ij[0] < 0): 259 | x = a_i[0] - x 260 | y = a_i[1] - y 261 | else: 262 | x = a_i[0] + x 263 | y = a_i[1] + y 264 | xyzarr[2] = [x, y, 0.0] 265 | 266 | for n in range(3, npart): 267 | # back-compute the xyz coordinates 268 | # from the positions of the last three atoms 269 | r = rlist[n-1] 270 | theta = alist[n-2] * np.pi / 180.0 271 | phi = dlist[n-3] * np.pi / 180.0 272 | 273 | sinTheta = np.sin(theta) 274 | cosTheta = np.cos(theta) 275 | sinPhi = np.sin(phi) 276 | cosPhi = np.cos(phi) 277 | 278 | x = r * cosTheta 279 | y = r * cosPhi * sinTheta 280 | z = r * sinPhi * sinTheta 281 | 282 | i = rconnect[n-1] - 1 283 | j = aconnect[n-2] - 1 284 | k = dconnect[n-3] - 1 285 | a = xyzarr[k] 286 | b = xyzarr[j] 287 | c = xyzarr[i] 288 | 289 | ab = b - a 290 | bc = c - b 291 | bc = bc / np.linalg.norm(bc) 292 | nv = np.cross(ab, bc) 293 | nv = nv / np.linalg.norm(nv) 294 | ncbc = np.cross(nv, bc) 295 | 296 | new_x = c[0] - bc[0] * x + ncbc[0] * y + nv[0] * z 297 | new_y = c[1] - bc[1] * x + ncbc[1] * y + nv[1] * z 298 | new_z = c[2] - bc[2] * x + ncbc[2] * y + nv[2] * z 299 | xyzarr[n] = [new_x, new_y, new_z] 300 | 301 | # print results 302 | for i in range(npart): 303 | print('{:<4s}\t{:>11.5f}\t{:>11.5f}\t{:>11.5f}'.format(atomnames[i], xyzarr[i][0], xyzarr[i][1], xyzarr[i][2])) 304 | --------------------------------------------------------------------------------