### Install pip, setuptools, and numpy Source: https://maserasgroup-repo.github.io/pyssian/readme_link.html Installs and upgrades pip, then installs setuptools and numpy, which are required dependencies for pyssian. This step should proceed without errors. ```bash $ python -m pip install pip $ python -m pip install --upgrade pip $ python -m pip install setuptools $ python -m pip install numpy ``` -------------------------------- ### TestLink103 setup and initialization Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/tests/test_linkjobparsers.html Sets up the test environment for Link103 and verifies basic initialization properties. ```python @classmethod def setUpClass(cls): cls.testfile = TEST_FILEDIR.joinpath('l103.txt') cls.parametersfile = TEST_FILEDIR.joinpath('l103_parameters.txt') cls.derivativesfile = TEST_FILEDIR.joinpath('l103_derivatives.txt') cls.convergencefile = TEST_FILEDIR.joinpath('l103_convergence.txt') # Read and store the Examples with open(cls.testfile,'r') as F: txt = F.read() cls.objects = [Link103(i) for i in txt.split(SMARK)] ``` ```python def test_init(self): msg = 'Incorrect parsing of Link103' for obj in self.objects: self.assertTrue(bool(obj.text),msg) self.assertEqual(obj.number,103,msg) self.assertTrue(bool(obj.mode),msg) ``` -------------------------------- ### TestLink101 setup and initialization Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/tests/test_linkjobparsers.html Sets up the test environment for Link101 and verifies basic initialization properties. ```python @classmethod def setUpClass(cls): cls.testfile = TEST_FILEDIR.joinpath('l101.txt') cls.charge_spin_solutions = [(-1,2),(0,2),(2,2),(2,2)] # Read and store the Examples with open(cls.testfile,'r') as F: txt = F.read() cls.objects = [Link101(i) for i in txt.split(SMARK)] ``` ```python def test_init(self): msg = 'Incorrect parsing of Link101' for obj in self.objects: self.assertTrue(bool(obj.text),msg) self.assertEqual(obj.number,101) self.assertTrue(obj.charge is not None,msg) self.assertTrue(obj.spin is not None,msg) ``` -------------------------------- ### TestLink716 Class Setup Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/tests/test_linkjobparsers.html Defines the test class for Link716 and initializes test files and objects in setUpClass. ```python class TestLink716(unittest.TestCase): @classmethod def setUpClass(cls): cls.testfile = TEST_FILEDIR.joinpath('l716.txt') cls.dipolefile = TEST_FILEDIR.joinpath('l716_redipole.txt') cls.Thermofile = TEST_FILEDIR.joinpath('l716_reThermo.txt') cls.EContribfile = TEST_FILEDIR.joinpath('l716_reEContrib.txt') cls.IRSpectrumfile = TEST_FILEDIR.joinpath('l716_reIRSpectrum.txt') cls.Frequenciesfile = TEST_FILEDIR.joinpath('l716_reFrequencies.txt') cls.freqtextfile = TEST_FILEDIR.joinpath('l716_refreqtxt.txt') cls.freqdispfile = TEST_FILEDIR.joinpath('l716_refreqdisplacements.txt') # Read and store the Examples with open(cls.testfile,'r') as F: txt = F.read() cls.objects = [Link716(i) for i in txt.split(SMARK)] ``` -------------------------------- ### Install pyssian from compressed archive Source: https://maserasgroup-repo.github.io/pyssian/readme_link.html Installs pyssian directly from a compressed source archive (pyssian.tar.gz) downloaded from the source. ```bash $ python -m pip install pyssian.tar.gz ``` -------------------------------- ### Install pyssian from PyPI Source: https://maserasgroup-repo.github.io/pyssian/readme_link.html Installs the pyssian package from the Python Package Index (PyPI). Requires Python 3.6 or newer and the setuptools and numpy libraries. ```bash $ python -m pip install pyssian ``` -------------------------------- ### Test class for chemistryutils functions Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/tests/test_chemistryutils.html Defines the ChemistryUtilsTest class with setUp and test methods. It imports is_basis and is_method from pyssian.chemistryutils and unittest. The setUp method initializes lists of valid and fake basis sets, methods, and usual keywords. Each test method checks that valid inputs are recognized and fake inputs are not. ```python from pyssian.chemistryutils import is_basis,is_method import unittest [docs] class ChemistryUtilsTest(unittest.TestCase): [docs] def setUp(self): self.Valid_Basis = '6-311+g(d,p) 6-31g* cc-pVTZ D95V* LanL2DZ SDD28 Def2SVP UGBS2P2++'.split() self.Fake_Basis = '6-311g+(d,p) 6-31*g ccpVTZ D96V* LanL2TZ SDD Def2SP UGBS2++P2'.split() self.Valid_Methods = 'ub3lyp mp2 casscf ccsd(t) rm062x WB97XD pbepbe'.split() self.Fake_Methods = 'bu3lyp pm2 bw97xd m06-2x pbepbe0'.split() self.Usual_Keywords = 'opt freq scrf scf #p calcfc empiricaldispersion'.split() [docs] def test_valid_isbasis(self): msg = 'Valid basis not properly recognized' for valid in self.Valid_Basis: self.assertTrue(is_basis(valid),msg) [docs] def test_fake_isbasis(self): msg = 'Fake basis recognized as valid' for fake in self.Fake_Basis: self.assertFalse(is_basis(fake),msg) [docs] def test_valid_ismethod(self): msg = 'Valid method not properly recognized' for valid in self.Valid_Methods: self.assertTrue(is_method(valid),msg) [docs] def test_fake_ismethod(self): msg = 'Fake method recognized as valid' for fake in self.Fake_Methods: self.assertFalse(is_method(fake),msg) [docs] def test_usual_keywords(self): msg1 = 'Keyword recognized as basis' msg2 = 'Keyword recognized as method' for keyword in self.Usual_Keywords: self.assertFalse(is_basis(keyword),msg1) self.assertFalse(is_method(keyword),msg2) ``` -------------------------------- ### Install Python 3.7 via deadsnakes PPA Source: https://maserasgroup-repo.github.io/pyssian/readme_link.html Adds the deadsnakes PPA and installs Python 3.7 and its development headers when the default repositories do not provide them. ```bash $ sudo add-apt-repository ppa:deadsnakes/ppa $ sudo apt-get update $ sudo apt-get install python3.7 python3.7-dev ``` -------------------------------- ### Build pyssian documentation with Sphinx Source: https://maserasgroup-repo.github.io/pyssian/readme_link.html Builds the documentation by navigating to the sphinx folder, installing the required packages from requirements.txt, and running make html. The resulting HTML documentation can be opened from the _docs/html folder. ```bash $ cd sphinx/ $ python -m pip install -r requirements.txt $ make html ``` -------------------------------- ### GaussianInFile container: __init__, __repr__, __str__, __len__, __enter__, __exit__ Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/gaussianclasses.html Initialization and dunder methods for the GaussianInFile container class. The constructor accepts a file-like object, None, or a path; when a path is given it opens the file in append mode and seeks to the start if the file is not empty. The string representation joins jobs with '--Link1--' and pads with newlines to end with three newlines. Context manager methods delegate to the underlying file object. ```python def __init__(self,file=None): # Do Something if isinstance(file,io.TextIOBase): self._file = file elif file is None: self._file = None else: self._file = open(file,'a+') if self._file.tell() != 0: self._file.seek(0) self.jobs = [] ``` ```python def __repr__(self): cls = type(self).__name__ file = self._file.name.split("/")[-1] #size = len(self) return f'<{cls}({file} with njobs={len(self.jobs)})>' ``` ```python def __str__(self): str_repr = '\n\n--Link1--\n'.join([str(job).rstrip() for job in self.jobs]) # It is better to enfoce the condition here than for every # possible case of reading a file or adding the tail if not str_repr.endswith('\n\n\n'): n = 3 - str_repr[-3:].count('\n') str_repr += '\n'*n return str_repr ``` ```python def __len__(self): return len(str(self)) ``` ```python def __enter__(self): ''' Wrapper to have similar behaviour to "_io.TextIOWrapper" ''' return self ``` ```python def __exit__(self, exc_type, exc_value, traceback): ''' Wrapper to have similar behaviour to "_io.TextIOWrapper" ''' return self._file.__exit__(exc_type, exc_value, traceback) ``` -------------------------------- ### Link1._locate_commandline() Source: https://maserasgroup-repo.github.io/pyssian/pyssian.linkjobparsers.html Uses regex expressions compiled as class attributes to search the gaussian commands, which start with a '#'. Fails silently. Populates the commandline attribute. ```APIDOC ## Link1._locate_commandline() ### Description Uses regex expressions compiled as class attributes to search the gaussian commands, which start with a '#'. Fails silently. Populates the commandline attribute. ### Method Method ### Signature _locate_commandline() ### Populates - **commandline** (str) - Contains the information of the gaussian commands (defaults to an empty string). ``` -------------------------------- ### Set up test class TestLink122 Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/tests/test_linkjobparsers.html Class-level setup for TestLink122, reading a test file and creating Link122 objects from its content split by SMARK. Defines expected solution lists for complex energy, BSSE correction, and fragment energies. ```python @classmethod def setUpClass(cls): cls.testfile = TEST_FILEDIR.joinpath('l122.txt') cls.re_complex_solutions = [ '-622.598617397384', '-554.437959704946' ] cls.re_bsse_solutions = [ '0.000785012282', '0.023214737127' ] cls.re_fragments_solutions = [ '-622.391294173148', '-553.667179856454' ] # Read and store the Examples with open(cls.testfile,'r') as F: txt = F.read() cls.objects = [Link122(i) for i in txt.split(SMARK)] ``` -------------------------------- ### parse_preprocessing method signature Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/gaussianclasses.html Starts the parse_preprocessing method, which parses Link 0 keyword lines into a dictionary representation. The provided code shows the method signature and docstring only. ```python def parse_preprocessing(self,lines): """ Parses the lines that contain the Link 0 keywords and transforms them into a dictionary representation. """ ``` -------------------------------- ### Run pyssian tests Source: https://maserasgroup-repo.github.io/pyssian/readme_link.html Runs the pyssian test suite using Python's unittest module with verbose output. Run this after installing pyssian. ```bash $ python -m unittest -v pyssian.tests ``` -------------------------------- ### Link1 attributes Source: https://maserasgroup-repo.github.io/pyssian/examples_link.html Shows how to get the first Link1 object and access its attributes: commandline, nprocs, mem, link0, IOps, and info (info will be deprecated). ```python # From the file Get the first Link1 l1 = GOF.get_links(1)[0] # Attributes of Link1 l1.commandline l1.nprocs l1.mem l1.link0 l1.IOps l1.info # Will be deprecated in the future ``` -------------------------------- ### GaussianFile.enforce_continuous_chk(basename=None) Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/gaussianclasses.html Enforces that the chk of job i-1 is retained and a copy of it is used at the start of job i. ```APIDOC ## GaussianFile.enforce_continuous_chk(basename=None) ### Description Enforces that the chk of job i-1 is retained and a copy of it is used at the start of job i. ### Method enforce_continuous_chk ### Parameters - **basename** (str) - Optional - basename of the chk to use, if none is provided it defaults to the one of the first job. ### Returns None ``` -------------------------------- ### commandline_as_str Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/gaussianclasses.html Transforms the commandline attribute to a suitable string representation. The command line starts with '#p' if extra_printout is True, otherwise '#'. Each key-value pair is formatted appropriately. ```APIDOC ## commandline_as_str ### Description Transforms the commandline attribute to a suitable string representation. The command line starts with '#p' if extra_printout is True, otherwise '#'. Each key-value pair is formatted appropriately. ### Method commandline_as_str() ### Parameters None ### Returns - **str** - String corresponding to the commandline of the input file. ``` -------------------------------- ### Get links by ID across InternalJobs Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/gaussianclasses.html Returns a list of links with the given IDs across all InternalJobs. Uses `chain` to flatten the lists. ```python LinkLists = [IntJob.get_links(*LinkIds) for IntJob in self.InternalJobs] return list(chain(*LinkLists)) ``` -------------------------------- ### get_links(*LinkIds) Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/gaussianclasses.html Wrapper method to get a list of Links with certain Ids. It filters the Links list by the provided link numbers and returns them in the order they appear in the file. ```APIDOC ## get_links(*LinkIds) ### Description Wrapper Method to get a list of Links with certain Ids. ### Method get_links(*LinkIds) ### Parameters #### *LinkIds (int) - Required - Integers that correspond to the type of links to be returned. ### Returns - **list** - List of Link Objects ordered by appearance in the file and filtered by Link Number. ### Example ```python # Get links with IDs 1 and 2 links = obj.get_links(1, 2) ``` ``` -------------------------------- ### Install Python 3.7 on Ubuntu 18.04 Source: https://maserasgroup-repo.github.io/pyssian/readme_link.html Installs Python 3.7 and its development headers on Ubuntu 18.04 LTS. This is part of installing the dependencies for pyssian. ```bash $ sudo apt-get update $ sudo apt-get install python3.7 python3.7-dev ``` -------------------------------- ### Opening GaussianOutFile Source: https://maserasgroup-repo.github.io/pyssian/examples_link.html Demonstrates three ways to open a Gaussian output file: using a context manager, manual opening and closing, or passing an existing file object. ```python from pyssian import GaussianOutFile outputfile = 'myfile.log' # Example 1 with GaussianOutFile(outputfile) as GOF1: GOF1.read() # Example 2 GOF2 = GaussianOutFile(outputfile) GOF2.read() GOF2.close() # Example 3 with open(outputfile,'r') as F: GOF3 = GaussianOutFile(F) GOF3.read() ``` -------------------------------- ### Creating a continuation input file Source: https://maserasgroup-repo.github.io/pyssian/examples_link.html Demonstrates how to extract geometry and calculation parameters from a failed Gaussian output file to create a new input file for continuing the optimization. ```python from pyssian import GaussianInFile, GaussianOutFile from pyssian.classutils import Geometry with GaussianOutFile('old_calculation.log') as GOF: GOF.read() # Get the last geometry of the calculation geom = Geometry.from_L202(GOF.get_links(202)[-1]) # Get the Link1 of the GaussianOutFile l1 = GOF.get_links(1)[0] # Extract the calculation type and commands commandline = l1.commandline nprocs = l1.nprocs mem = l1.mem preprocessing = l1.link0 # Get Charge and spin from Link101 Link101 = GOF.get_links(101)[0] charge = Link101.charge spin = Link101.spin # Now write the new input file with GaussianInFile('new_calculation.com') as GIF: GIF.parse_commandline([commandline,]) # We can instead set a dict for the variable GIF.commandline # "GIF.commandline = {'opt':'','freq':'NoRamman','b3lyp':''}" # but using parse_commandline is easier in this case. # we can also add keywords to the command line either directly # GIF.commandline['keyword'] = '' # or with a method # GIF.add_kwd('keyword') GIF.preprocessing = {key:'' for key in Link0} GIF.preprocessing['nprocshared'] = nprocs GIF.preprocessing['mem'] = mem GIF.title = 'New Title' GIF.spin = spin GIF.charge = charge GIF.geometry = geom GIF.write() ``` -------------------------------- ### Creating GaussianInFile from existing files Source: https://maserasgroup-repo.github.io/pyssian/examples_link.html Shows how to create a new input file by combining geometry and theory settings from two existing Gaussian input files. ```python from pyssian import GaussianInFile initial_theory_file = 'InitialTheory.com' initial_geometry_file = 'InitialGeometry.com' output_file = 'generated.com' with GaussianInFile(initial_theory_file) as theory_file: theory_file.read() with GaussianInFile(initial_geometry_file) as geometry_file: geometry_file.read() old_geometry = theory_file.geometry # In case we want to use it somewhere else theory_file.geometry = geometry_file.geometry theory_file.method = 'b3lyp' theory_file.write(filepath=output_file) ``` -------------------------------- ### Link202.__init__(text, asEmpty=False) Source: https://maserasgroup-repo.github.io/pyssian/pyssian.linkjobparsers.html Constructor for the Link202 class. Initializes the parser with the text output from l202.exe and an optional flag to skip parsing. ```APIDOC ## Link202.__init__(text, asEmpty=False) ### Description Initializes a Link202 instance with the provided text and parsing flag. ### Parameters - **text** (str) - Required - Text that corresponds to the output of the l202.exe. - **asEmpty** (bool) - Optional - Flag to not parse and store the information of the text. Defaults to False. ### Returns None ``` -------------------------------- ### GaussianOutFile.get_links(*LinkIds) Source: https://maserasgroup-repo.github.io/pyssian/pyssian.gaussianclasses.html Wrapper method to get a list of Links with certain IDs across the different Internal Jobs. ```APIDOC ## GaussianOutFile.get_links(*LinkIds) ### Description Wrapper method to get a list of Links with certain IDs across the different Internal Jobs. ### Method get_links ### Parameters - **LinkIds** (int) - Required - Integers that correspond to the type of links to be returned. ### Returns - **list** - List of Links matching the given IDs. ``` -------------------------------- ### Link914.__init__(text, asEmpty=False) Source: https://maserasgroup-repo.github.io/pyssian/pyssian.linkjobparsers.html Constructor for the Link914 class. Initializes the parser with the output text from l914.exe and an optional flag to skip parsing. ```APIDOC ## Link914.__init__(text, asEmpty=False) ### Description Initializes a Link914 instance to represent and parse the output of l914.exe, which contains information about TDDFT excited states. ### Parameters - **text** (str) - Required - The text that corresponds to the output of the l914.exe. - **asEmpty** (bool) - Optional - Flag to not parse and store the information of the text. Defaults to False. ### Returns None ``` -------------------------------- ### GaussianInFile.__init__(file=None) Source: https://maserasgroup-repo.github.io/pyssian/pyssian.gaussianclasses.html Constructor for the GaussianInFile class. Accepts a file object or filename to initialize the input file representation. ```APIDOC ## GaussianInFile.__init__(file=None) ### Description Initializes a GaussianInFile object. If a file is provided, it parses the file and populates the object's attributes. ### Parameters - **file** (io.TextIOBase or str) - Optional - File instance (result of open(filename, 'r')) or valid filename. ### Returns None ### Notes - Does not parse ONIOM or MM calculation inputs. - Not tested for z-matrix inputs. ``` -------------------------------- ### Link502 and Link508 energies Source: https://maserasgroup-repo.github.io/pyssian/examples_link.html Shows how to get all Link502 and Link508 objects and extract their energies, filtering out None values. ```python list_of_links = GOF.get_links(502,508) energies = [link.energy for link in list_of_links if link.energy is not None] ``` -------------------------------- ### Link202 attributes Source: https://maserasgroup-repo.github.io/pyssian/examples_link.html Shows how to access orientation, distance matrix, print orientation, and get atom mapping from a Link202 object. ```python l202 = GOF[-1].get_links(202)[0] l202.orientation l202.DistanceMatrix l202.print_orientation() l202.get_atom_mapping() ``` -------------------------------- ### GaussianOutFile.__init__(file, parselist=None) Source: https://maserasgroup-repo.github.io/pyssian/pyssian.gaussianclasses.html Constructor for the GaussianOutFile class. Initializes the parser with a file object or filename and an optional list of link IDs to parse. ```APIDOC ## GaussianOutFile.__init__(file, parselist=None) ### Description Initializes a GaussianOutFile instance. Accepts a file object or a filename. The file must have the #p printout enabled to be parsable. ### Method Constructor ### Parameters - **file** (io.TextIOBase or str) - Required - File instance (result of open(filename, 'r')) or valid filename. - **parselist** (list) - Optional - List of integers representing which types of Links to parse. Default is None. ### Returns None ``` -------------------------------- ### Instantiate Cube from File Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/classutils.html Creates a new Cube instance by reading and parsing data from an existing .cube file. ```python @classmethod def from_file(cls,file): """ Creates a Cube instance from a cube file. Parameters ---------- file : str A valid filename to an existing .cube file. Returns ------- Cube Instantiated cube from the file. """ newcube = cls() with open(file,'r') as F: lines = F.readlines() _iter = lines.__iter__() newcube.handle_title_lines(_iter) newcube.read_origin_line(_iter) newcube.read_basis_lines(_iter) newcube.read_atoms_lines(_iter) newcube.read_MO_lines(_iter) newcube.read_matrix_lines(_iter) return newcube ``` -------------------------------- ### test_init_empty Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/tests/test_linkjobparsers.html Verifies that Link601 initializes correctly when the asEmpty flag is set to True. ```python def test_init_empty(self): msg = 'Incorrect empty initialization of Link502' obj = Link601('Some Text',asEmpty=True) self.assertFalse(bool(obj.text),msg) self.assertEqual(obj.number,601) ``` -------------------------------- ### Follow an ongoing Gaussian calculation Source: https://maserasgroup-repo.github.io/pyssian/examples_link.html Shows how to use GaussianOutFile with update() to monitor a running Gaussian calculation, printing the last item and sleeping between updates. ```python from time import sleep from pyssian import GaussianOutFile GOF = GaussianOutFile('myoutput.log',[-1,]) GOF.update(clean=False) print(GOF[-1][-1]) sleep(10) GOF.update(clean=False) print(GOF[-1][-1]) GOF.close() ``` -------------------------------- ### enforce_continuous_chk(basename=None) Source: https://maserasgroup-repo.github.io/pyssian/pyssian.gaussianclasses.html Enforces that the chk of job i-1 is retained and a copy is used at the start of job i. This creates a continuous checkpoint chain across linked jobs. ```APIDOC ## enforce_continuous_chk(basename=None) ### Description Enforces that the chk of job i-1 is retained and a copy of it is used at the start of job i. For an example with two jobs, the first link0 section will look like: %chk=basename_job0.chk, then the link0 of the second job will look like: %chk=basename_job1.chk. ### Parameters - **basename** (str, optional) - Basename of the chk to use. If none is provided, it defaults to the one of the first job. ``` -------------------------------- ### GaussianInFile.commandline_as_str() Source: https://maserasgroup-repo.github.io/pyssian/pyssian.gaussianclasses.html Returns the command line as a string representation. ```APIDOC ## GaussianInFile.commandline_as_str() ### Description Transforms the commandline attribute to a suitable string representation. ### Parameters None ### Returns - **str** - String corresponding to the commandline of the input file. ``` -------------------------------- ### Link1._locate_link0() Source: https://maserasgroup-repo.github.io/pyssian/pyssian.linkjobparsers.html Uses regex expressions compiled as class attributes to search the link0 options (specified with a % at the start of the option). Populates nprocs, mem, and link0 attributes. ```APIDOC ## Link1._locate_link0() ### Description Uses regex expressions compiled as class attributes to search the link0 options (specified with a % at the start of the option). Populates nprocs, mem, and link0 attributes. ### Method Method ### Signature _locate_link0() ### Populates - **nprocs** (int) - Contains the number of the %nprocshared link0 option. Defaults to None. - **mem** (str) - Contains the right hand side of the %mem link0 option. Defaults to None. - **link0** (list) - List of lines containing the link0 specifications. If none is found defaults to an empty list. ``` -------------------------------- ### Link1 constructor Source: https://maserasgroup-repo.github.io/pyssian/pyssian.linkjobparsers.html Initializes a Link1 instance with the text output from l1.exe and an optional flag to skip parsing. ```APIDOC ## Link1 constructor ### Description Initializes a Link1 instance with the text output from l1.exe and an optional flag to skip parsing. ### Method Constructor ### Signature Link1(text, asEmpty=False) ### Parameters - **text** (str) - Required - Text that corresponds to the output of the l1.exe. - **asEmpty** (bool) - Optional - Flag to not parse and store the information of the text. Defaults to False. ### Returns A Link1 instance. ``` -------------------------------- ### GaussianClasses Class Initialization Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/gaussianclasses.html The __init__ method initializes the Gaussian input file structure, setting up dictionaries for preprocessing and command line options, and defining the default structure of the input file. ```python def __init__(self,file=None): # Do Something if isinstance(file,io.TextIOBase): self._file = file elif file is None: self._file = None else: self._file = open(file,'a+') if self._file.tell() != 0: self._file.seek(0) self._txt = '' self.preprocessing = dict() # In the G16 Manual "Link 0 Commands" self.commandline = dict() # In the G16 Manual "Route Section" self.title = '' self._method = '' self._basis = '' self.spin = 1 self.charge = 0 self.geometry = '' # In the G16 Manual "Molecule Specification" self.tail = [] # In the G16 Manual "Optional additional sections" self.extra_printout = True self.structure = '{preprocessing}\n{commandline}\n\n' self.structure += '{title}\n\n' self.structure += '{charge} {spin}\n{geometry}\n' self.structure += '{tail}\n\n' ``` -------------------------------- ### Performing arithmetic on Cube files Source: https://maserasgroup-repo.github.io/pyssian/examples_link.html Shows how to load multiple cube files and perform arithmetic operations on them using the Cube class. ```python from pyssian.classutils import Cube MO_1 = Cube.from_file('MO_01.cube') MO_2 = Cube.from_file('MO_02.cube') MO_3 = Cube.from_file('MO_03.cube') FinalCube = MO_1*2 + MO_2 - MO_3**2 FinalCube.write('Final.cube') ``` -------------------------------- ### Parsing specific GaussianOutFile links Source: https://maserasgroup-repo.github.io/pyssian/examples_link.html Demonstrates how to parse only specific links by providing a list of link numbers to the GaussianOutFile constructor. ```python outputfile = 'myfile.log' with GaussianOutFile(outputfile,[1,103,202,502,9999]) as GOF: GOF.read() ``` -------------------------------- ### GaussianOutFile Source: https://maserasgroup-repo.github.io/pyssian/_sources/pyssian.gaussianclasses.rst.txt Class for parsing Gaussian output files. Supports context manager usage similar to 'with open(file) as F:...'. Will only parse a Gaussian Output File that has the '#p'. ```APIDOC ## GaussianOutFile ### Description Class for parsing Gaussian output files. Supports context manager usage similar to 'with open(file) as F:...'. Will only parse a Gaussian Output File that has the '#p'. ### Methods - **print_file_structure** - Prints the structure of the output file. - **get_links** - Retrieves linked calculations from the output file. - **update** - Updates the output file object. - **read** - Reads the output file. - **clean** - Cleans the output file data. ``` -------------------------------- ### GaussianInFile constructor Source: https://maserasgroup-repo.github.io/pyssian/pyssian.gaussianclasses.html Initializes a GaussianInFile object by reading the content of a Gaussian input file. The name parameter is used to represent the file. ```APIDOC ## GaussianInFile(name: str) ### Description Creates a GaussianInFile object by reading the content of the specified file. The file content is read and stored for parsing. ### Parameters - **name** (str) - Required - Name to represent the GaussianInFile. ### Returns - A populated GaussianInFile object. ### Return Type - GaussianInFile ### Example ```python with open('somefile.com', 'r') as F: text = F.read() gaussian_file = GaussianInFile(name='somefile.com') ``` ``` -------------------------------- ### GaussianInFile.read(): parse file into jobs Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/gaussianclasses.html Reads the entire file content and splits it on '--Link1--' to create GaussianInFile objects for each job. If no file is set, it returns without doing anything. ```python def read(self): """ Reads the file and populates the appropiate attributes. """ if self._file is None: return txt = self._file.read() self.jobs = [GaussianInFile.from_str(job.lstrip()) for job in txt.split('--Link1--')] ``` -------------------------------- ### Cube.from_file Source: https://maserasgroup-repo.github.io/pyssian/pyssian.classutils.html Creates a Cube instance from a cube file. ```APIDOC ## Cube.from_file ### Description Creates a Cube instance from a cube file. ### Method classmethod ### Signature `from_file(file)` ### Parameters - **file** (str) - A valid filename to an existing .cube file. ### Returns - **Cube** - Instantiated cube from the file. ``` -------------------------------- ### MultiGaussianInFile(file=None) Source: https://maserasgroup-repo.github.io/pyssian/pyssian.gaussianclasses.html Constructor for the MultiGaussianInFile class. Initializes a container for multiple GaussianInFile objects linked together. ```APIDOC ## MultiGaussianInFile(file=None) ### Description Constructor for the MultiGaussianInFile class. Initializes a container for multiple GaussianInFile objects linked together. ### Parameters - **file** (io.TextIOBase or str, optional) - File instance (result of open(filename, 'r')) or valid filename. Default is None. ### Attributes - **jobs** (list) - List providing access to each individual GaussianInFile object representing each linked calculation. ``` -------------------------------- ### TestLink101 empty initialization and parsing Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/tests/test_linkjobparsers.html Tests empty initialization and the final parsed charge and spin values. ```python def test_init_empty(self): msg = 'Incorrect empty initialization of Link101' obj = Link101('-> Input Text',asEmpty=True) self.assertFalse(bool(obj.text),msg) self.assertEqual(obj.number,101) ``` ```python def test_charge_spin(self): msg = '{} is not properly parsed'.format for item,obj in zip(self.charge_spin_solutions,self.objects): charge, spin = item self.assertTrue(obj.charge == charge ,msg('charge')) self.assertTrue(obj.spin == spin, msg('spin')) ``` -------------------------------- ### Create GaussianInFile from string Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/gaussianclasses.html Initializes a GaussianInFile object by parsing a string containing Gaussian input file content. ```python @classmethod def from_str(cls,text): """ Creates a GaussianInFile object from a gaussian input file read as a string, parses it and populates the attributes of the class. Parameters ---------- text : str Contents of a Gaussian input file as a string. i.e. .. code:: python with open('somefile.com','r') as F: text = F.read() name : str Name to represent the GaussianInFile Returns ------- GaussianInFile A populated GaussianInFile object """ new = cls() new._file = text.split('\n') new.read() return new ``` -------------------------------- ### TestLink103 empty initialization Source: https://maserasgroup-repo.github.io/pyssian/_modules/pyssian/tests/test_linkjobparsers.html Verifies that empty initialization of Link103 results in empty or None attributes. ```python def test_init_empty(self): msg = 'Incorrect empty initialization of Link101' obj = Link103('-> Input Text',asEmpty=True) attrs = ['mode','state','convergence', 'parameters', 'derivatives', 'stepnumber', 'scanpoint'] for attr in attrs: test = getattr(obj,attr) self.assertTrue(not bool(test) or test is None) ``` -------------------------------- ### GaussianInFile.add_kwd(keyword, where=None) Source: https://maserasgroup-repo.github.io/pyssian/pyssian.gaussianclasses.html Adds a keyword to the command line. Optionally adds it as a suboption of another keyword. ```APIDOC ## GaussianInFile.add_kwd(keyword, where=None) ### Description Adds a keyword to the command line. If 'where' is provided, the keyword is added as a suboption of that keyword. ### Parameters - **keyword** (str) - Required - Keyword to add to the command line. - **where** (str, optional) - Optional - If provided, adds the keyword as a suboption of the 'where' keyword (e.g., add_kwd('smd', where='scrf')). ### Returns None ``` -------------------------------- ### DirectoryTree.newpath Source: https://maserasgroup-repo.github.io/pyssian/pyssian.classutils.html Takes a path rooted to the previous root and prepares it to be rooted in the new root. ```APIDOC ## DirectoryTree.newpath ### Description Takes a path rooted to the previous root and prepares it to be rooted in the new root. ### Method instance method ### Signature `newpath(path)` ### Parameters - **path** - The path to be re-rooted. ``` -------------------------------- ### GaussianOutFile.update(clean=True, FinalPrint=False) Source: https://maserasgroup-repo.github.io/pyssian/pyssian.gaussianclasses.html Tries to fetch new data. If it exists it parses it appropriately otherwise it fails silently. ```APIDOC ## GaussianOutFile.update(clean=True, FinalPrint=False) ### Description Tries to fetch new data. If it exists it parses it appropriately otherwise it fails silently. ### Method update ### Parameters - **clean** (Bool) - Optional - If True removes all the EmptyLinkJobs found. Default is True. - **FinalPrint** (Bool) - Optional - If True after a normal execution has finished it will print in the console a message to notify the user. Default is False. ### Returns None ``` -------------------------------- ### GaussianInFile.add_l0_kwd(keyword, where=None) Source: https://maserasgroup-repo.github.io/pyssian/pyssian.gaussianclasses.html Adds a keyword to the preprocessing dictionary (Link0 keywords). Optionally adds it as a suboption. ```APIDOC ## GaussianInFile.add_l0_kwd(keyword, where=None) ### Description Adds a keyword to the preprocessing dictionary. If 'where' is provided, the keyword is added as a suboption of that keyword. ### Parameters - **keyword** (str) - Required - Keyword to add to the preprocessing. - **where** (str, optional) - Optional - If provided, adds the keyword as a suboption of the 'where' keyword (e.g., add_l0_kwd('job1.chk', where='chk')). ### Returns None ``` -------------------------------- ### GaussianInFile Source: https://maserasgroup-repo.github.io/pyssian/_sources/pyssian.gaussianclasses.rst.txt Class for reading and writing Gaussian input files. Supports context manager usage similar to 'with open(file) as F:...'. Does not parse ONIOM or MM calculation inputs, and is not tested for z-matrix inputs. ```APIDOC ## GaussianInFile ### Description Class for reading and writing Gaussian input files. Supports context manager usage similar to 'with open(file) as F:...'. Does not parse ONIOM or MM calculation inputs, and is not tested for z-matrix inputs. ### Usage ```python with GaussianInFile('input.com') as f: # read or modify ``` ### Notes - Does not parse ONIOM calculation inputs - Does not parse MM calculation inputs - Not tested for z-matrix inputs ```