Skip to content

Commit

Permalink
cleanup and improved warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dkratzert committed Apr 30, 2017
1 parent 22d9276 commit 74c3872
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 65 deletions.
12 changes: 6 additions & 6 deletions atomhandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def get_atoms_resinumber(self, atom):
resinum = '0'
if len(resinum) > 4:
print('*** Invalid residue number in {}'.format(atom))
sys.exit(-1)
sys.exit()
return str(resinum)
else:
return '0'
Expand Down Expand Up @@ -428,7 +428,7 @@ def get_atomcoordinates(self, atoms):
i = i.upper()
if i not in list(atom_dict):
print('\n*** Atom "{}" not found in res file! ***'.format(i))
sys.exit(0)
sys.exit()
return atom_dict

def get_atom_line_numbers(self, atoms):
Expand Down Expand Up @@ -539,13 +539,13 @@ def check_source_target(db_source_atoms, res_target_atoms, dbatoms):
if nsrc != ntrg:
print('*** Number of source and target atoms/peaks is different!! '
'({} and {} atoms/peaks) ***'.format(nsrc, ntrg))
sys.exit(False)
sys.exit()
# do the source atoms exist at all?:
for i in db_source_atoms:
i = i.upper()
if i not in temp:
print('\n*** Atom {} not found in database entry! ***'.format(i))
sys.exit(False)
sys.exit()
return True


Expand Down Expand Up @@ -653,7 +653,7 @@ def set_sfac_table(self):
sfac.append(i) # get appended to sfac
if i not in self.elements:
print('*** Error, atom {} not valid ***'.format(i))
sys.exit(False)
sys.exit()
for i in range(1, len(sfac+explicit_scat)+1):
i = str(i).upper()
unit.append(i)
Expand Down Expand Up @@ -837,7 +837,7 @@ def get_fragment_number_scheme(self, extranames=[]):
print('passed all {} tests!'.format(attempted))
else:
print('{} of {} tests failed'.format(failed, attempted))
sys.exit()




Expand Down
60 changes: 30 additions & 30 deletions dbfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ def find_db_tags(self):
diff = c1 - c2
duplicates = list(diff.elements())
for i in duplicates:
print('\n*** Duplicate database entry "{}" found! Please remove/rename ' \
'second entry\nand/or check all end tags in the database dsr_usr_db.txt or dsr_db.txt. ***'.format(
duplicates.pop()))
sys.exit(False)
print('\n*** Duplicate database entry "{}" found! Please remove/rename '
'second entry\nand/or check all end tags in the database dsr_usr_db.txt '
'or dsr_db.txt. ***'.format(duplicates.pop()))
sys.exit()
# # sort lower-case:
dbnames.sort(key=lambda x: x[0].lower())
return dbnames
Expand Down Expand Up @@ -358,9 +358,9 @@ def get_residue_from_head(head, fragment=''):
del resiline[n]
try:
return resiline[1].upper()
except(IndexError):
except IndexError:
print('*** Invalid residue definition in database entry {}. ***'.format(fragment))
sys.exit(False)
sys.exit()
return False

def get_fragment_atoms(self, fragment, db_name, line):
Expand Down Expand Up @@ -398,11 +398,11 @@ def get_fragment_atoms(self, fragment, db_name, line):
print('*** Database entry of "{}" in line {} of "{}.txt" is corrupt. '
'No atoms found! ***'.format(fragment, line, db_name))
print('*** Have you really followed the syntax? ***')
sys.exit(False)
sys.exit()
if not end:
print('*** Could not find end of dbentry for fragment "{}" in line {} of "{}.txt". '
'Check your database. ***'.format(fragment, line, db_name))
sys.exit(False)
sys.exit()
if self.invert:
atoms = invert_dbatoms_coordinates(atoms)
return atoms
Expand Down Expand Up @@ -444,7 +444,7 @@ def get_head_lines(self, fragment, db, line):
print('*** Error. No cell parameters found in the database entry ' \
'of "{}" ***'.format(fragment))
print('*** Please add these parameters! ***')
sys.exit(False)
sys.exit()
# nhead is list of strings
head = unwrap_head_lines(head)
return head, fragline, comment
Expand Down Expand Up @@ -520,7 +520,7 @@ def check_consistency(self, fragment):
if len(dbentry['fragline']) != 8:
print('*** The line starting with "FRAG" in the database entry of {} is not correct. ***\n '
'*** Are the cell parameters really correct? "FRAG 17 a b c alpha beta gamma" ***\n'.format(fragment))
sys.exit(False)
sys.exit()
return True

def get_sum_formula(self, fragment):
Expand Down Expand Up @@ -552,9 +552,10 @@ def check_db_atom_consistency(self, fragment):
while dbatoms:
at = dbatoms.pop()
if at in dbatoms:
print('*** Duplicate atom {0} in database entry "{1}" ({2}) ' \
'found! Check your database... ***'.format(at, fragment, self.get_name_from_fragment(fragment)))
sys.exit(-1)
print('*** Duplicate atom {0} in database entry "{1}" ({2}) '
'found! Check your database... ***'
.format(at, fragment, self.get_name_from_fragment(fragment)))
sys.exit()

def check_db_header_consistency(self, fragment):
"""
Expand All @@ -579,7 +580,6 @@ def check_db_header_consistency(self, fragment):
status = False
print('*** Bad line in header of database entry "{}" found! ({}.txt) ***'.format(fragment, db))
print(line)
# sys.exit(status)
if line[:4] in RESTRAINT_CARDS:
line = line[5:].split()
for i in line:
Expand All @@ -593,8 +593,8 @@ def check_db_header_consistency(self, fragment):
atom = atom.upper()
if atom not in atoms:
status = False
print('\n*** Unknown atom "{}" in restraints of "{}: {}". ***'.format(atom, fragment,
self.get_name_from_fragment(fragment)))
print('\n*** Unknown atom "{}" in restraints of "{}: {}". ***'
.format(atom, fragment, self.get_name_from_fragment(fragment)))
if not status:
print('*** Check database entry. ***\n')
sys.exit(status)
Expand Down Expand Up @@ -683,13 +683,13 @@ def search_for_error_response(self, fragment):
print_search_results(result)

def get_atoms_from_fragment(self, fragment):
'''
"""
returns the atoms from the dbentry:
[['O1', '1', '0.01453', '-1.6659', '-0.10966'],
['C1', '1', '0.00146', '-0.26814', '-0.06351'], ... ]
:param fragment: fragment name
:type fragment: string
'''
"""
fragment = fragment.lower()
try:
return self._db_all_dict[fragment]['atoms']
Expand Down Expand Up @@ -846,12 +846,12 @@ def get_gradefiles(self, grade_tar_file):
if grade_base_filename[1] == '.tgz':
try:
gradefile = tarfile.open(grade_tar_file) # , encoding="ascii")
except(IOError):
except IOError:
print('No such file or directory: {}'.format(grade_tar_file))
sys.exit(0)
sys.exit()
else:
print('*** File {} is not a valid file to import from ***'.format(grade_base_filename[1]))
sys.exit(0)
sys.exit()
pdbfile = False
dfixfile = False
for i in gradefile.getnames():
Expand Down Expand Up @@ -1028,8 +1028,8 @@ def bild_grade_db_entry(self):
name = name.decode()
resi_name = name
if not self._db_tags:
print('Unable to import fragment. Database is empty.')
sys.exit(False)
print('*** Unable to import fragment. Database is empty. ***')
sys.exit()
for i in self._db_tags:
while resi_name == i[0]:
num = num + 1
Expand All @@ -1055,9 +1055,9 @@ def import_error(self, filename):
'''
warns for import errors
'''
print('Unable to import GRADE file {}'.format(filename))
print('GRADE import relies on GRADE v1.100 and up.')
sys.exit(False)
print('*** Unable to import GRADE file {}'.format(filename))
print('GRADE import relies on GRADE v1.100 and up. ***')
sys.exit()

def write_user_database(self):
"""
Expand Down Expand Up @@ -1088,9 +1088,9 @@ def write_user_database(self):
dbentry = '<{}> \n{} \nRESI {} \n{} \n{} \n{} \n</{}>\n''\
'.format(resi_name, comment, resi_name, head, cell, atoms, resi_name)
f.write(dbentry)
except(IOError) as e:
except IOError as e:
print(e)
sys.exit(-1)
sys.exit()
# try to write existing dbentries:
try:
with open(self.user_db_path, 'a+') as fu:
Expand All @@ -1109,9 +1109,9 @@ def write_user_database(self):
dbentry = '\n<{}> \nREM {} \nRESI {} \n{} \n{} \n{} \n</{}>\n' \
''.format(name, comment, resi_name, head, fragline, atoms, name)
fu.write(dbentry)
except(IOError) as e:
except IOError as e:
print(e)
sys.exit(-1)
sys.exit()
print('User database successfully updated.')


Expand Down
8 changes: 3 additions & 5 deletions dsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
program_name = '\n'+((width//2)-9)*'-'+' D S R - v{} '.format(VERSION)+((width//2)-8)*'-'

# TODO and ideas:
'''
"""
- Add Rcomplete
From SHELXL user guide:
Expand All @@ -49,7 +49,7 @@
-> learn JANA
-> What do I need to change?
'''
"""


class DSR():
Expand Down Expand Up @@ -100,9 +100,7 @@ def __init__(self, options):
self.gdb = global_DB(invert=self.invert)
except Exception as e: # @UnusedVariable
print("*** Initializing the database failed ***")
#print(self.helpmsg)
raise
#sys.exit()
# List of database Fragments:
if self.list_db_csv:
print('DSR version: {}'.format(VERSION))
Expand Down Expand Up @@ -153,7 +151,7 @@ def __init__(self, options):
if self.import_grade:
mog = ImportGRADE(self.import_grade, self.invert)
mog.write_user_database()
sys.exit(1)
sys.exit()
if not any(list(vars(self.options.all_options).values())+[self.res_file]):
self.options.error()
if self.res_file == False:
Expand Down
2 changes: 1 addition & 1 deletion dsrparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def find_dsr_command(self, line=False):
indexnum = misc.find_multi_lines(self._reslist, self._dsr_regex)
try:
line_number = int(indexnum[0])
except(IndexError):
except IndexError:
print('*** no proper DSR command found! \n'
'Have you really saved your .res file? ***\n')
sys.exit()
Expand Down
5 changes: 2 additions & 3 deletions export.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import atomhandling as at
from atoms import Element
from dbfile import global_DB
from misc import wrap_headlines
from restraints import Restraints

__metaclass__ = type # use new-style classes
Expand Down Expand Up @@ -226,8 +227,6 @@ def format_atoms_for_export(self, fragname, gui=False):
'C5 6 2.98081 10.44432 9.51725', 'C6 6 3.92045 9.74974 10.25408',
'C7 6 3.53891 8.69091 11.05301']
#>>> print(exp.format_atoms_for_export(fragname="", gui=True))
#sys.exit()
"""
fragname = fragname.lower()
el = Element()
Expand Down Expand Up @@ -314,7 +313,7 @@ def write_res_file(self, fragment):
except IOError:
print('*** Could not write file {} ***'.format(resfile))
import sys
sys.exit(-1)
sys.exit()
f.close()


Expand Down
2 changes: 1 addition & 1 deletion misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def remove_file(filename, exit_dsr=False, terminate=False):
pgrogname = terminate
pgrogname.terminate()
if exit_dsr:
sys.exit(0)
sys.exit()


def copy_file(source, target):
Expand Down
2 changes: 1 addition & 1 deletion options.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
try:
from argparse import RawTextHelpFormatter
except ImportError:
print('\nYour Python version is incompatible with DSR! \nPlease use Python 2.7 or above.\n')
print('\n*** Your Python version is incompatible with DSR! \nPlease use Python 2.7 or above. ***\n')
sys.exit()
from argparse import ArgumentParser, SUPPRESS

Expand Down
6 changes: 2 additions & 4 deletions pyperclip.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,8 @@ def xselGetClipboard():
getcb = qtGetClipboard
setcb = qtSetClipboard
except:
# import sys
print('\nDSR requires Pyperclip to export fragments to the clipboard.')
print('Pyperclip requires the xclip command or the gtk or PyQt4 module installed.\n')
# sys.exit()
print('\n*** DSR requires Pyperclip to export fragments to the clipboard.')
print('Pyperclip requires the xclip command or the gtk or PyQt4 module installed. ***\n')
try:
copy = setcb
paste = getcb
Expand Down
Loading

0 comments on commit 74c3872

Please sign in to comment.