Author: bugman Date: Fri Jun 10 15:08:46 2011 New Revision: 12968 URL: http://svn.gna.org/viewcvs/relax?rev=12968&view=rev Log: Generating new user function 'read_xyz()'. This is Han's patch https://gna.org/task/download.php?file_id=13153 attached to the task http://gna.org/task/?7404. The user function 'read_xyz()' was generated and modified in the generic_fns/structure/main.py based on the function 'read_pdb()'. Modified: branches/xyz/generic_fns/structure/main.py Modified: branches/xyz/generic_fns/structure/main.py URL: http://svn.gna.org/viewcvs/relax/branches/xyz/generic_fns/structure/main.py?rev=12968&r1=12967&r2=12968&view=diff ============================================================================== --- branches/xyz/generic_fns/structure/main.py (original) +++ branches/xyz/generic_fns/structure/main.py Fri Jun 10 15:08:46 2011 @@ -364,6 +364,68 @@ molmol.open_pdb() +def read_xyz(file=None, dir=None, read_mol=None, set_mol_name=None, read_model=None, set_model_num=None, verbosity=1, fail=True): + """The XYZ loading function. + + + @keyword file: The name of the XYZ file to read. + @type file: str + @keyword dir: The directory where the XYZ file is located. If set to None, then the + file will be searched for in the current directory. + @type dir: str or None + @keyword read_mol: The molecule(s) to read from the file, independent of model. + If set to None, then all molecules will be loaded. + @type read_mol: None, int, or list of int + @keyword set_mol_name: Set the names of the molecules which are loaded. If set to None, then + the molecules will be automatically labelled based on the file name or + other information. + @type set_mol_name: None, str, or list of str + @keyword read_model: The XYZ model to extract from the file. If set to None, then all models + will be loaded. + @type read_model: None, int, or list of int + @keyword set_model_num: Set the model number of the loaded molecule. If set to None, then the + XYZ model numbers will be preserved, if they exist. + @type set_model_num: None, int, or list of int + @keyword fail: A flag which, if True, will cause a RelaxError to be raised if the XYZ + file does not exist. If False, then a RelaxWarning will be trown + instead. + @type fail: bool + @keyword verbosity: The amount of information to print to screen. Zero corresponds to + minimal output while higher values increase the amount of output. The + default value is 1. + @type verbosity: int + @raise RelaxFileError: If the fail flag is set, then a RelaxError is raised if the XYZ file + does not exist. + """ + + # Test if the current data pipe exists. + pipes.test() + + # The file path. + file_path = get_file_path(file, dir) + + # Try adding '.xyz' to the end of the file path, if the file can't be found. + if not access(file_path, F_OK): + file_path_orig = file_path + file_path = file_path + '.xyz' + + # Test if the file exists. + if not access(file_path, F_OK): + if fail: + raise RelaxFileError('XYZ', file_path_orig) + else: + warn(RelaxNoPDBFileWarning(file_path)) + return + + + # Place the structural object into the relax data store. + if not hasattr(cdp, 'structure'): + cdp.structure = Internal() + + # Load the structures. + cdp.structure.load_xyz(file_path, read_mol=read_mol, set_mol_name=set_mol_name, read_model=read_model, set_model_num=set_model_num, verbosity=verbosity) + + def set_vector(spin=None, xh_vect=None): """Place the XH unit vector into the spin container object.