forked from vtlim/off_psi4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadFromXYZ.py
More file actions
56 lines (41 loc) · 1.56 KB
/
Copy pathloadFromXYZ.py
File metadata and controls
56 lines (41 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
## Write new coordinates from an XYZ file to an existing mol2
## file with old coordinates. Helpful for VMD optimization and
## keeping consistent atom numbering for RMSD comparisons.
## Usage: python loadFromXYZ.py -m initial.mol2 -x final.xyz -o final.mol2
import os, sys
import openeye.oechem as oechem
import argparse
### ------------------- Script -------------------
def main(**kwargs):
outfn = opt['fout']
# Open input files.
mifs = oechem.oemolistream()
if not mifs.open(opt['fmol2']):
oechem.OEThrow.Warning("Unable to open %s for reading" % opt['fmol2'])
return
xifs = oechem.oemolistream()
if not xifs.open(opt['fxyz']):
oechem.OEThrow.Warning("Unable to open %s for reading" % opt['fxyz'])
return
mmol = mifs.GetOEMols().next()
xmol = xifs.GetOEMols().next()
mmol.SetCoords(xmol.GetCoords())
ofs = oechem.oemolostream()
if not ofs.open(outfn):
oechem.OEThrow.Fatal("Unable to open %s for writing" % outfn)
oechem.OEWriteConstMolecule(ofs, mmol)
ofs.close()
mifs.close()
xifs.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-m", "--fmol2",
help="Reference mol2 file which new coordinates will be loaded into.")
parser.add_argument("-x", "--fxyz",
help="XYZ file with new coordinates to load into mol2 file.")
parser.add_argument("-o", "--fout",
help="Name of the output mol2 file.")
args = parser.parse_args()
opt = vars(args)
main(**opt)