Author: bugman Date: Mon Jan 26 15:24:53 2009 New Revision: 8647 URL: http://svn.gna.org/viewcvs/relax?rev=8647&view=rev Log: Created __convert_to_id() to convert from Xplor atom string to relax atom id. Modified: branches/ave_noe/generic_fns/xplor.py Modified: branches/ave_noe/generic_fns/xplor.py URL: http://svn.gna.org/viewcvs/relax/branches/ave_noe/generic_fns/xplor.py?rev=8647&r1=8646&r2=8647&view=diff ============================================================================== --- branches/ave_noe/generic_fns/xplor.py (original) +++ branches/ave_noe/generic_fns/xplor.py Mon Jan 26 15:24:53 2009 @@ -26,6 +26,47 @@ # Python module imports. from re import search from string import split + +# relax module imports. +from relax_errors import RelaxError + + +def __convert_to_id(string): + """Convert the string into a relax atom id representation. + + @param string: The Xplor atom string. + @type string: str + @return: The relax atom id. + @rtype: str + """ + + # Split up the string by the 'and' statements. + data = split(string, 'and') + + # Loop over the data. + relax_id = '' + for i in range(len(data)): + # Split by whitespace. + info = split(data[i]) + + # Don't know what this is! + if len(info) != 2: + raise RelaxError, "Cannot convert the Xplor atom string '%s' to relax format." % string + + # A molecule identifier. + if info[0] == 'segid': + relax_id = relax_id + '#' + info[1] + + # A residue identifier. + elif info[0] == 'resid': + relax_id = relax_id + ':' + info[1] + + # An atom identifier. + elif info[0] == 'name': + relax_id = relax_id + '@' + info[1] + + # Return the relax id. + return relax_id def parse_noe_restraints(lines): @@ -78,7 +119,7 @@ atom = atom + lines[line_index][char_index] # Convert the atom data to a relax atom id. - data[-1][0] = atom + data[-1][0] = __convert_to_id(atom) # Extract the second atom string. atom = '' @@ -107,7 +148,7 @@ atom = atom + lines[line_index][char_index] # Convert the atom data to a relax atom id. - data[-1][1] = atom + data[-1][1] = __convert_to_id(atom) # The rest of the data (NOE restraint info). info = split(lines[line_index][char_index+1:])