### get(cifname, outfname, method=3, var_dict={}, isoformat='topas', selection=1, subcif='', specify=False, basis=[]) Source: https://frandsengroup.github.io/isopydistort/isoget.html Interacts with the ISODISTORT website to get distortion modes and save the output to a file. ```APIDOC ## get(cifname, outfname, method=3, var_dict={}, isoformat='topas', selection=1, subcif='', specify=False, basis=[]) ### Description Interacts with the ISODISTORT website to get distortion modes. This function uploads a CIF file, processes it using the specified ISODISTORT method, and saves the resulting data to the provided output filename. ### Parameters - **cifname** (str) - Required - The name of the local cif file you want to use. - **outfname** (str) - Required - The name of the file where you want the ISODISTORT output saved. - **method** (int) - Optional - Method number to be used by the ISODISTORT server (currently 3 or 4). Default is 3. - **var_dict** (dict) - Optional - Variables to pass to ISODISTORT to set up the subgroup symmetry, lattice, and basis. - **isoformat** (str) - Optional - Format of the output file requested from the ISODISTORT server. Allowed values: 'isovizdistortion', 'isovizdiffraction', 'structurefile', 'distortionfile', 'domains', 'primary', 'modesdetails', 'completemodesdetails', 'topas', 'fullprof', 'irreps', 'tree'. Default is 'topas'. - **selection** (int) - Optional - The number of the desired distortion from the list of possible distortions provided by ISODISTORT, starting from 1. Default is 1. - **subcif** (str) - Optional - Sub-CIF file path. - **specify** (bool) - Optional - Flag to specify settings. - **basis** (list) - Optional - Basis configuration list. ``` -------------------------------- ### get(cifname, outfname, method=3, var_dict={}, isoformat='topas', selection=1, subcif='', specify=False, basis=[]) Source: https://frandsengroup.github.io/isopydistort/isoget.html Interacts with the ISODISTORT website to retrieve distortion modes based on a provided CIF file and configuration parameters. ```APIDOC ## get(cifname, outfname, method=3, var_dict={}, isoformat='topas', selection=1, subcif='', specify=False, basis=[]) ### Description Interacts with the ISODISTORT website to get distortion modes. This function handles the communication with the ISODISTORT server to process structural data. ### Parameters - **cifname** (str) - Required - The name of the local cif file you want to use. - **outfname** (str) - Required - The name of the file where you want the ISODISTORT output saved. - **method** (int) - Optional - Method number to be used by the ISODISTORT server (currently 3 or 4). - **var_dict** (dict) - Optional - Variables to pass to ISODISTORT to set up the subgroup symmetry, lattice, and basis. - **isoformat** (str) - Optional - The format of the output. - **selection** (int) - Optional - Selection parameter for the server. - **subcif** (str) - Optional - Subcif configuration string. - **specify** (bool) - Optional - Whether to specify a custom basis. - **basis** (list) - Optional - List of 9 elements defining the basis if specify is True. ``` -------------------------------- ### get(cifname, outfname, method=3, var_dict={}, isoformat='topas', selection=1, subcif='', specify=False, basis=[]) Source: https://frandsengroup.github.io/isopydistort/isoget.html Interacts with the ISODISTORT website to process CIF files and retrieve distortion modes based on the specified method and format. ```APIDOC ## get(cifname, outfname, method=3, var_dict={}, isoformat='topas', selection=1, subcif='', specify=False, basis=[]) ### Description Interacts with the ISODISTORT website to get distortion modes. This function handles the upload of a parent CIF file, applies the requested distortion method, and saves the output to a specified file. ### Parameters - **cifname** (str) - Required - The name of the local CIF file to use. - **outfname** (str) - Required - The name of the file where the ISODISTORT output will be saved. - **method** (int) - Optional - Method number to be used by the ISODISTORT server (currently 3 or 4). Default is 3. - **var_dict** (dict) - Optional - Variables to pass to ISODISTORT to set up subgroup symmetry, lattice, and basis. - **isoformat** (str) - Optional - Format of the output file requested. Allowed values: 'isovizdistortion', 'isovizdiffraction', 'structurefile', 'distortionfile', 'domains', 'primary', 'modesdetails', 'completemodesdetails', 'topas', 'fullprof', 'irreps', 'tree'. Default is 'topas'. - **selection** (int) - Optional - The number of the desired distortion from the list provided by ISODISTORT. Default is 1. - **subcif** (str) - Optional - Sub-CIF file identifier for method 4. - **specify** (bool) - Optional - Flag for method 4 configuration. - **basis** (list) - Optional - Basis configuration for method 4. ``` -------------------------------- ### Initialize isopydistort package Source: https://frandsengroup.github.io/isopydistort/index.html The package entry point imports the isoget module to enable web server interfacing. ```python #!/usr/bin/env python ############################################################################## # # isopydistort by Frandsen Group # Benjamin A. Frandsen benfrandsen@byu.edu # (c) 2023 Benjamin Allen Frandsen # All rights reserved # # File coded by: Benjamin Frandsen # # See AUTHORS.txt for a list of people who contributed. # See LICENSE.txt for license information. # ############################################################################## """Tools for interfacing with the ISODISTORT web server. """ import isopydistort.isoget # End of file ``` -------------------------------- ### Execute test suite Source: https://frandsengroup.github.io/isopydistort/tests/tests.html Standard entry point for running the unittest suite. ```python if __name__ == '__main__': unittest.main() ``` -------------------------------- ### Configure ISODISTORT basis and parameters Source: https://frandsengroup.github.io/isopydistort/isoget.html Sets up the basis variables and default parameters for the ISODISTORT request. ```python if specify == True: basis_vars = ["basis11", "basis12", "basis13", "basis21", "basis22", "basis23", "basis31", "basis32", "basis33"] if not basis: print("No basis specified. Exiting...") print("Try specifying a basis or setting specify to False") if len(basis) != 9: print("Incorrect number of elements for basis, expected 9") else: data['inputbasis'] = 'specify' for i in range(len(basis_vars)): data[basis_vars[i]] = f'{basis[i]}' data['chooseorigin'] = False data['trynearest'] = True data['dmax'] = 1 data['zeromodes'] = False for key, value in var_dict.items(): data[key] = value return data ``` -------------------------------- ### Initialize ISODISTORT interaction Source: https://frandsengroup.github.io/isopydistort/isoget.html Main entry point for interacting with the ISODISTORT website to retrieve distortion modes. ```python def get(cifname, outfname, method=3, var_dict={}, isoformat='topas', selection=1, subcif = "", specify = False, basis = []): """Interacts with the ISODISTORT website to get distortion modes. Args: cifname (str): The name of the local cif file you want to use. outfname (str): The name of the file where you want the ISODISTORT output saved. method (int): Method number to be used by the ISODISTORT server. The currently available method numbers are 3 and 4. var_dict (dict): Variables to pass to ISODISTORT to set up the subgroup symmetry, lattice, and basis. The required dictionary keys depend on the method number chosen, as described below. ``` -------------------------------- ### Method 3 Configuration Keys Source: https://frandsengroup.github.io/isopydistort/isoget.html Required dictionary keys for Method 3 configuration. ```python 'subgroupsym' = '1 P1 C1-1' 'pointgroupsym' = '0' 'latticetype' = 'direct' 'centering' = 'd' (for default) 'basis11' = '1' 'basis12' = '0' 'basis13' = '0' 'basis21' = '0' 'basis22' = '1' ``` -------------------------------- ### Method 3 Configuration Defaults Source: https://frandsengroup.github.io/isopydistort/isoget.html Default dictionary keys and values for Method 3, which defaults to P1 symmetry and an identity matrix for the supercell basis. ```python 'subgroupsym' = '1 P1 C1-1' 'pointgroupsym' = '0' 'latticetype' = 'direct' 'centering' = 'd' (for default) 'basis11' = '1' 'basis12' = '0' 'basis13' = '0' 'basis21' = '0' 'basis22' = '1' 'basis23' = '0' 'basis31' = '0' 'basis32' = '0' 'basis33' = '1' ``` -------------------------------- ### Execute unit tests for isopydistort Source: https://frandsengroup.github.io/isopydistort/tests/tests.html Run the unit tests using the Python interpreter. ```bash python -m isopydistort.tests.tests ``` -------------------------------- ### Configure ISODISTORT Basis Parameters Source: https://frandsengroup.github.io/isopydistort/isoget.html Set the basis configuration values for the ISODISTORT server request. ```text 'basis23' = '0' 'basis31' = '0' 'basis32' = '0' 'basis33' = '1' ``` -------------------------------- ### Build test suite Source: https://frandsengroup.github.io/isopydistort/tests/index.html Constructs a unittest.TestSuite object by dynamically importing modules defined in the modulenames list. ```python def testsuite(): '''Build a unit tests suite for the isopydistort package. Return a unittest.TestSuite object. ''' import unittest modulenames = ''' isopydistort.tests.tests '''.split() suite = unittest.TestSuite() loader = unittest.defaultTestLoader mobj = None for mname in modulenames: exec ('import %s as mobj' % mname) suite.addTests(loader.loadTestsFromModule(mobj)) return suite ``` -------------------------------- ### Execute unit tests Source: https://frandsengroup.github.io/isopydistort/tests/index.html Runs the full test suite and returns a unittest TestResult object. ```python def test(): '''Execute all unit tests for the isopydistort package. Return a unittest TestResult object. ''' import unittest suite = testsuite() runner = unittest.TextTestRunner() result = runner.run(suite) return result ``` -------------------------------- ### Download ISODISTORT output Source: https://frandsengroup.github.io/isopydistort/isoget.html Submits the final request to the ISODISTORT server and saves the resulting output to a file. ```python def _postDisplayDistort(data, fname): """Download the ISODISTORT output. """ out = requests.post(ISO_FORM_SITE, data=data) f = open(fname, 'wb') f.write(out.text.encode('utf-8')) f.close() ``` -------------------------------- ### Full module source code Source: https://frandsengroup.github.io/isopydistort/tests/index.html The complete source code for the isopydistort.tests module, including logger initialization and test suite management. ```python #!/usr/bin/env python ############################################################################## # # isopydistort by Frandsen Group # Benjamin A. Frandsen benfrandsen@byu.edu # (c) 2023 Benjamin Allen Frandsen # All rights reserved # # File coded by: Benjamin Frandsen # # See AUTHORS.txt for a list of people who contributed. # See LICENSE.txt for license information. # ############################################################################## """Unit tests for isopydistort. """ # create logger instance for the tests subpackage import logging logging.basicConfig() logger = logging.getLogger(__name__) del logging def testsuite(): '''Build a unit tests suite for the isopydistort package. Return a unittest.TestSuite object. ''' import unittest modulenames = ''' isopydistort.tests.tests '''.split() suite = unittest.TestSuite() loader = unittest.defaultTestLoader mobj = None for mname in modulenames: exec ('import %s as mobj' % mname) suite.addTests(loader.loadTestsFromModule(mobj)) return suite def test(): '''Execute all unit tests for the isopydistort package. Return a unittest TestResult object. ''' import unittest suite = testsuite() runner = unittest.TextTestRunner() result = runner.run(suite) return result # End of file ``` -------------------------------- ### Define ISODISTORT Output Formats Source: https://frandsengroup.github.io/isopydistort/isoget.html List of valid string values for the isoformat parameter to specify the requested output file type. ```text 'isovizdistortion' 'isovizdiffraction' 'structurefile' 'distortionfile' 'domains' 'primary' 'modesdetails' 'completemodesdetails' 'topas' 'fullprof' 'irreps' 'tree' ``` -------------------------------- ### Test ISODISTORT connection and retrieval Source: https://frandsengroup.github.io/isopydistort/tests/tests.html Verifies connection to the ISODISTORT server and validates the output format of the retrieved data. ```python class testBasic(unittest.TestCase): def test_get(self): print('Testing connection to ISODISTORT server...') path = os.path.dirname(os.path.abspath(__file__)) cif = find('hexMnTe.cif',path) options = {'basis11':'0', 'basis12':'-1','basis21':'1','basis22':'0'} fnameiso = os.path.join(path, "MnTe_iso.txt") isopydistort.isoget.get(cif, fnameiso, var_dict=options) f = open(fnameiso, 'r') lines = f.readlines() f.close() for idx, line in enumerate(lines): if 'mode definitions' in line: testIdx = int(1.0*idx) teststr = lines[testIdx + 5].strip()[:8] self.assertEqual(teststr, 'prm !a5') ``` ```python def test_get(self): print('Testing connection to ISODISTORT server...') path = os.path.dirname(os.path.abspath(__file__)) cif = find('hexMnTe.cif',path) options = {'basis11':'0', 'basis12':'-1','basis21':'1','basis22':'0'} fnameiso = os.path.join(path, "MnTe_iso.txt") isopydistort.isoget.get(cif, fnameiso, var_dict=options) f = open(fnameiso, 'r') lines = f.readlines() f.close() for idx, line in enumerate(lines): if 'mode definitions' in line: testIdx = int(1.0*idx) teststr = lines[testIdx + 5].strip()[:8] self.assertEqual(teststr, 'prm !a5') ``` -------------------------------- ### Unit test implementation for isopydistort Source: https://frandsengroup.github.io/isopydistort/tests/tests.html The test suite verifies the retrieval of ISODISTORT data by comparing output against a known CIF file and expected mode definitions. ```python #!/usr/bin/env python ############################################################################## # # isopydistort by Frandsen Group # Benjamin A. Frandsen benfrandsen@byu.edu # (c) 2023 Benjamin Allen Frandsen # All rights reserved # # File coded by: Benjamin Frandsen # # See AUTHORS.txt for a list of people who contributed. # See LICENSE.txt for license information. # ############################################################################## """Unit tests basic isopydistort functionalities. Execute via python -m isopydistort.tests.tests """ import unittest import isopydistort import sys import os ############################################################################## def find(name, path): for root, dirs, files in os.walk(path): if name in files: return os.path.join(root, name) class testBasic(unittest.TestCase): def test_get(self): print('Testing connection to ISODISTORT server...') path = os.path.dirname(os.path.abspath(__file__)) cif = find('hexMnTe.cif',path) options = {'basis11':'0', 'basis12':'-1','basis21':'1','basis22':'0'} fnameiso = os.path.join(path, "MnTe_iso.txt") isopydistort.isoget.get(cif, fnameiso, var_dict=options) f = open(fnameiso, 'r') lines = f.readlines() f.close() for idx, line in enumerate(lines): if 'mode definitions' in line: testIdx = int(1.0*idx) teststr = lines[testIdx + 5].strip()[:8] self.assertEqual(teststr, 'prm !a5') ``` -------------------------------- ### Interface with ISODISTORT Source: https://frandsengroup.github.io/isopydistort/isoget.html The module uses the requests library to handle file uploads and form submissions to the ISODISTORT web service. ```python #!/usr/bin/env python ############################################################################## # # isopydistort by Frandsen Group # Benjamin A. Frandsen benfrandsen@byu.edu # (c) 2023 Benjamin Allen Frandsen # All rights reserved # # File coded by: Parker Hamilton, Tobias Bird, Ben Frandsen # # See AUTHORS.txt for a list of people who contributed. # See LICENSE.txt for license information. # We acknowledge Brian Toby and Robert Von Dreele as the first to develop a # python interface to ISODISTORT, which served as a valuable starting point # for this package. Their work can be found as part of the GSAS-II software at # https://subversion.xray.aps.anl.gov/trac/pyGSAS/browser/trunk/ISODISTORT.py ############################################################################## """Tools to interface with ISODISTORT""" import requests ISO_UPLOAD_SITE = "https://iso.byu.edu/iso/isodistortuploadfile.php" ISO_FORM_SITE = "https://iso.byu.edu/iso/isodistortform.php" def _uploadCIF(cif): """Upload CIF to ISODISTORT. """ f = open(cif, 'rb') up = {'toProcess': (cif, f), } out = requests.post(ISO_UPLOAD_SITE, files=up).text f.close() start = out.index("VALUE=") start = out.index('"', start + 1) + 1 end = out.index('"', start) fname = out[start:end] return fname def _postParentCIF(fname): #posts initially uploaded CIF, sets all data up = {'filename': fname, 'input': 'uploadparentcif'} out = requests.post(ISO_FORM_SITE, up) data = {} line_iter = out.iter_lines() for line in line_iter: if b'INPUT TYPE="hidden"' in line: items = line.decode('utf-8').split(' ', 3) name = items[2].split('=')[1].strip('"') val = items[3].split('=', 1)[1].strip('>"') data[name] = val return out, data def _setDatam3(out, data, var_dict = {}, selection = 1): """sets necessary data for method 3 - rolls in postIsosubgroup and part of postParentm3""" line_iter = out.iter_lines() for line in line_iter: if b"Method 3" in line: break for line in line_iter: if b'INPUT TYPE="hidden"' in line: items = line.decode('utf-8').split(' ', 3) name = items[2].split('=')[1].strip('"') val = items[3].split('=', 1)[1].strip('>"') data[name] = val if b'Method 4' in line: break data['subgroupsym'] = '1 P1 C1-1' data['pointgroupsym'] = '0' data['latticetype'] = 'direct' data['centering'] = 'd' data['basis11'] = '1' data['basis12'] = '0' data['basis13'] = '0' data['basis21'] = '0' data['basis22'] = '1' data['basis23'] = '0' data['basis31'] = '0' data['basis32'] = '0' data['basis33'] = '1' for key, value in var_dict.items(): data[key] = value out = requests.post(ISO_FORM_SITE, data=data) data = {} line_iter = out.iter_lines() for line in line_iter: if b"
' in line: break return data def _setDatam4(data, subcif, specify = False, basis = [], var_dict = {}): subfname = _uploadCIF(subcif) data['input'] = 'uploadsubgroupcif' data['filename'] = subfname out = requests.post(ISO_FORM_SITE, data=data) line_iter = out.iter_lines() # for line in line_iter: # print(line.decode('utf-8')) for line in line_iter: if b'INPUT TYPE="hidden"' in line: items = line.decode('utf-8').split(' ', 3) name = items[2].split('=')[1].strip('"') val = items[3].split('=', 1)[1].strip('>"') data[name] = val if specify == False and b'OPTION VALUE=' in line: data['inputbasis'] = 'list' items = line.decode('utf-8').split(' ', 1) data['basisselect'] = items[1].split('=')[1].split(">")[0].strip('"') print(items[1].split('=')[1].split(">")[0].strip('"')) data['input'] = 'distort' data['origintype'] = 'method4' ``` -------------------------------- ### Find file in directory tree Source: https://frandsengroup.github.io/isopydistort/tests/tests.html Locates a file by name within a specified directory path using os.walk. ```python def find(name, path): for root, dirs, files in os.walk(path): if name in files: return os.path.join(root, name) ``` -------------------------------- ### ISODISTORT Interaction Logic Source: https://frandsengroup.github.io/isopydistort/isoget.html Core logic for validating formats and methods before submitting requests to the ISODISTORT server. ```python ### check that the format and method number are acceptable formatlist = ['isovizdistortion', 'isovizdiffraction', 'structurefile', 'distortionfile', 'domains', 'primary', 'modesdetails', 'completemodesdetails', 'topas', 'fullprof', 'irreps', 'tree'] methodlist = [3,4] ### if everything is good, move on to the interaction with ISODISTORT if (isoformat in formatlist) and (method in methodlist): parentcif = _uploadCIF(cifname) out, data = _postParentCIF(parentcif) # use the correct post function for the user-supplied method number #data = eval('_postParentCIFm' + str(method) + '(parentcif, var_dict)') if method == 3: data = _setDatam3(out, data, var_dict = var_dict, selection = selection) if method == 4: data = _setDatam4(data, subcif, specify = specify, basis = basis, var_dict = var_dict) #data = _postIsoSubGroup(data, selection) data = _postDistort(data, isoformat) _postDisplayDistort(data, outfname) ### inform the user if there is a problem if isoformat not in formatlist: print('This is not a valid format. Acceptable options are:\n') print('isovizdistortion') print('isovizdiffraction') print('structurefile') print('distortionfile') print('domains') print('primary') print('modesdetails') print('completemodesdetails') print('topas') print('fullprof') print('irreps') print('tree\n') print('Please try again with one of these formats.') return if method not in methodlist: print('This is not a valid method number. Acceptable options are:\n') print(methodlist) print('Please try again with one of these methods.') print('Additional methods may become available in the future.') return ``` -------------------------------- ### Retrieve distortion modes from ISODISTORT Source: https://frandsengroup.github.io/isopydistort/isoget.html Use this function to automate the process of uploading a CIF file and requesting specific distortion data from the ISODISTORT server. Ensure the provided method number and output format are supported by the current API implementation. ```python def get(cifname, outfname, method=3, var_dict={}, isoformat='topas', selection=1, subcif = "", specify = False, basis = []): """Interacts with the ISODISTORT website to get distortion modes. Args: cifname (str): The name of the local cif file you want to use. outfname (str): The name of the file where you want the ISODISTORT output saved. method (int): Method number to be used by the ISODISTORT server. The currently available method numbers are 3 and 4. var_dict (dict): Variables to pass to ISODISTORT to set up the subgroup symmetry, lattice, and basis. The required dictionary keys depend on the method number chosen, as described below. Method 3: Keys and default values are given below. It defaults to P1 symmetry and an identity matrix for the supercell basis.\n 'subgroupsym' = '1 P1 C1-1'\n 'pointgroupsym' = '0'\n 'latticetype' = 'direct'\n 'centering' = 'd' (for default)\n 'basis11' = '1'\n 'basis12' = '0'\n 'basis13' = '0'\n 'basis21' = '0'\n 'basis22' = '1'\n 'basis23' = '0'\n 'basis31' = '0'\n 'basis32' = '0'\n 'basis33' = '1'\n Note that the 'subgroupsym' value can simply be the space group number (as a string) for the desired subgroup. It is not recommended to use the space group symbol alone, since this is not always read correctly. isoformat (str): format of the output file requested from the ISODISTORT server. Allowed values are:\n 'isovizdistortion'\n 'isovizdiffraction'\n 'structurefile'\n 'distortionfile'\n 'domains'\n 'primary'\n 'modesdetails'\n 'completemodesdetails'\n 'topas'\n 'fullprof'\n 'irreps'\n 'tree'\n See https://stokes.byu.edu/iso/isodistorthelp.php#savedist for information about each format. selection (int): The number of the desired distortion from the list of possible distortions provided by ISODISTORT, starting from 1 at the top and increasing as you move downward through the list. Default value is 1. """ ### check that the format and method number are acceptable formatlist = ['isovizdistortion', 'isovizdiffraction', 'structurefile', 'distortionfile', 'domains', 'primary', 'modesdetails', 'completemodesdetails', 'topas', 'fullprof', 'irreps', 'tree'] methodlist = [3,4] ### if everything is good, move on to the interaction with ISODISTORT if (isoformat in formatlist) and (method in methodlist): parentcif = _uploadCIF(cifname) out, data = _postParentCIF(parentcif) # use the correct post function for the user-supplied method number #data = eval('_postParentCIFm' + str(method) + '(parentcif, var_dict)') if method == 3: data = _setDatam3(out, data, var_dict = var_dict, selection = selection) if method == 4: data = _setDatam4(data, subcif, specify = specify, basis = basis, var_dict = var_dict) #data = _postIsoSubGroup(data, selection) data = _postDistort(data, isoformat) _postDisplayDistort(data, outfname) ### inform the user if there is a problem if isoformat not in formatlist: print('This is not a valid format. Acceptable options are:\n') print('isovizdistortion') print('isovizdiffraction') print('structurefile') print('distortionfile') print('domains') print('primary') print('modesdetails') print('completemodesdetails') print('topas') print('fullprof') print('irreps') print('tree\n') print('Please try again with one of these formats.') return if method not in methodlist: print('This is not a valid method number. Acceptable options are:\n') print(methodlist) print('Please try again with one of these methods.') print('Additional methods may become available in the future.') return ``` -------------------------------- ### Parse ISODISTORT form data Source: https://frandsengroup.github.io/isopydistort/isoget.html Processes the HTML response from the ISODISTORT server to extract hidden form fields and current settings. ```python def _postDistort(data, isoformat): """Prepare the data for downloading. """ out = requests.post(ISO_FORM_SITE, data=data) data = {} line_iter = out.iter_lines() for line in line_iter: if b"' in line: break data['origintype'] = isoformat return data ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.