Skip to content

Commit

Permalink
Merge pull request #274 from hjkgrp/tabs_coordinates
Browse files Browse the repository at this point in the history
optional flag for tab replacement with spaces
  • Loading branch information
gianmarco-terrones authored Oct 24, 2024
2 parents 6efb628 + 56c0df1 commit 4d4fea6
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions molSimplify/Classes/mol3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,20 +807,24 @@ def combine(self, mol, bond_to_add=[], dirty=False):
self.metals = None
return cmol

def coords(self):
def coords(self, no_tabs=False):
"""
Method to obtain string of coordinates in molecule.
Returns
-------
coord_string : string
String of molecular coordinates with atom identities in XYZ format.
no_tabs : bool, optional
Whether or not to use tabs in coordinate columns.
"""
coord_string = '' # initialize returning string
coord_string += "%d \n\n" % self.natoms
for atom in self.atoms:
xyz = atom.coords()
coord_string += "%s \t%f\t%f\t%f\n" % (atom.sym, xyz[0], xyz[1], xyz[2])
if no_tabs:
coord_string = coord_string.replace('\t', ' ' * 8)
return coord_string

def coordsvect(self):
Expand Down Expand Up @@ -2810,7 +2814,7 @@ def RCDistance(self, idx1, idx2, disti, distf, distint=0.05, writegeo=False, dir
temp_dist.writexyz(str(dir_name)+"/rc_"+str(str("{:.4f}".format(dist_val)))+'.xyz')
return temp_list

def returnxyz(self):
def returnxyz(self, no_tabs=False):
"""
Print XYZ info of mol3D class instance to stdout. To write to file
(more common), use writexyz() instead.
Expand All @@ -2819,12 +2823,16 @@ def returnxyz(self):
-------
XYZ : string
String of XYZ information from mol3D class.
no_tabs : bool, optional
Whether or not to use tabs in coordinate columns.
"""

ss = ''
for atom in self.atoms:
xyz = atom.coords()
ss += "%s \t%f\t%f\t%f\n" % (atom.sym, xyz[0], xyz[1], xyz[2])
if no_tabs:
ss = ss.replace('\t', ' ' * 8)
return (ss)

def readfromxyz(self, filename: str, ligand_unique_id=False, read_final_optim_step=False, readstring=False):
Expand Down Expand Up @@ -3616,7 +3624,7 @@ def writegxyz(self, filename):

def writexyz(self, filename, symbsonly=False, ignoreX=False,
ordering=False, writestring=False, withgraph=False,
specialheader=False):
specialheader=False, no_tabs=False):
"""
Write standard XYZ file.
Expand All @@ -3636,6 +3644,8 @@ def writexyz(self, filename, symbsonly=False, ignoreX=False,
Flag to write with graph (after XYZ) if True. Default is False. If True, sparse graph written.
specialheader : str, optional
String to write information into header. Default is False. If True, a special string is written.
no_tabs : bool, optional
Whether or not to use tabs in coordinate columns.
"""

Expand Down Expand Up @@ -3682,14 +3692,17 @@ def writexyz(self, filename, symbsonly=False, ignoreX=False,
tempstr += ' '+str(row2)+' S\n'
ss += tempstr

if no_tabs:
ss = ss.replace('\t', ' ' * 8)

if writestring:
return ss
else:
fname = filename.split('.xyz')[0]
with open(fname + '.xyz', 'w') as f:
f.write(ss)

def writemxyz(self, mol, filename):
def writemxyz(self, mol, filename, no_tabs=False):
"""
Write standard XYZ file with two molecules.
Expand All @@ -3699,6 +3712,8 @@ def writemxyz(self, mol, filename):
mol3D instance of second molecule.
filename : str
Path to XYZ file.
no_tabs : bool, optional
Whether or not to use tabs in coordinate columns.
"""
ss = '' # initialize returning string
Expand All @@ -3710,6 +3725,8 @@ def writemxyz(self, mol, filename):
for atom in mol.atoms:
xyz = atom.coords()
ss += "%s \t%f\t%f\t%f\n" % (atom.sym, xyz[0], xyz[1], xyz[2])
if no_tabs:
ss = ss.replace('\t', ' ' * 8)
fname = filename.split('.xyz')[0]
with open(fname + '.xyz', 'w') as f:
f.write(ss)
Expand Down

0 comments on commit 4d4fea6

Please sign in to comment.