How to use the cclib.io.ccread function in cclib

To help you get started, we’ve selected a few cclib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cclib / cclib / test / io / testxyzwriter.py View on Github external
def test_init(self):
        """Does the class initialize correctly?"""
        fpath = os.path.join(__datadir__, "data/ADF/basicADF2007.01/dvb_gopt.adfout")
        data = cclib.io.ccread(fpath)
        xyz = cclib.io.xyzwriter.XYZ(data)

        # The object should keep the ccData instance passed to its constructor.
        self.assertEqual(xyz.ccdata, data)
github cclib / cclib / test / io / testwfxwriter.py View on Github external
def test_programs(self):
        """Check other programs against reference data."""
        ref_file = "data/GAMESS/basicGAMESS-US2017/dvb_sp.out"
        # Skipping ORCA test until https://github.com/cclib/cclib/pull/394 is
        # merged.
        programs = {
            #'ORCA': "data/ORCA/basicORCA4.0/dvb_sp.out",
            'NWChem': "data/NWChem/basicNWChem6.5/dvb_sp_hf.out",
            'Psi': "data/Psi/basicPsi4.0/dvb_sp_rhf.out",
            'GAMESS-UK': "data/GAMESS-UK/basicGAMESS-UK8.0/dvb_sp_hf.out",
            'Firefly': "data/GAMESS/basicFirefly8.0/dvb_sp.out",
        }
        fpath_ref = os.path.join(__datadir__, ref_file)
        data_ref = cclib.io.ccread(fpath_ref)
        wfx_ref = cclib.io.wfxwriter.WFXWriter(data_ref)
        norm_mat_ref = wfx_ref._norm_mat()[0]
        mos_ref = wfx_ref._no_of_mos()

        for name in programs:
            fpath_prog = os.path.join(__datadir__, programs[name])
            data_prog = cclib.io.ccread(fpath_prog)
            wfx_prog = cclib.io.wfxwriter.WFXWriter(data_prog)

            norm_mat_prog = wfx_prog._norm_mat()[0]
            mos_prog = wfx_prog._no_of_mos()

            # Check if normalization matrix are matching.
            self.assertAlmostEqual(max(np.array(norm_mat_prog) -
                                       np.array(norm_mat_ref)), 0, places=5)
            # Check if number of orbitals to be printed are as expected.
github cclib / cclib / test / io / testwfxwriter.py View on Github external
def test_mo_normalization(self):
        """Check if MO section is printed correctly."""
        fpath = os.path.join(__datadir__,
                             "data/GAMESS/basicGAMESS-US2017/C_bigbasis.out")
        data = cclib.io.ccread(fpath)
        wfx = cclib.io.wfxwriter.WFXWriter(data)

        normalized_mocoeffs = wfx._normalized_mocoeffs()
        if len(data.homos) > 1:
            self.assertEqual(len(normalized_mocoeffs), wfx._no_electrons())
        else:
            self.assertEqual(len(normalized_mocoeffs), wfx._no_of_mos())
        self.assertEqual(len(normalized_mocoeffs[0]), wfx._no_of_prims())
github cclib / cclib / test / io / testmoldenwriter.py View on Github external
def test_atoms_section_size(self):
        """Check if size of Atoms section is equal to expected."""
        fpath = os.path.join(__datadir__,
                             "data/GAMESS/basicGAMESS-US2018/dvb_un_sp.out")
        data = cclib.io.ccread(fpath)
        writer = cclib.io.moldenwriter.MOLDEN(data)
        # Check size of Atoms section.
        self.assertEqual(len(writer._coords_from_ccdata(-1)), data.natom)
github cclib / cclib / test / io / testwfxwriter.py View on Github external
def test_mo_normalization_dat(self):
        """Check if MOs are normalized as expected."""
        fpath = os.path.join(__datadir__,
                             "data/GAMESS/basicGAMESS-US2017/dvb_sp.out")
        data = cclib.io.ccread(fpath)
        wfx = cclib.io.wfxwriter.WFXWriter(data)

        normalized_mocoeffs_wfx = wfx._normalized_mocoeffs()
        datfile = os.path.join(__datadir__,
                               "data/GAMESS/basicGAMESS-US2017/dvb_sp.dat")

        with open(datfile) as file:
            content = iter(file.readlines())

        normalized_mocoeffs_dat = []

        line = next(content)
        while 'TOP OF INPUT FILE FOR BADER' not in line:
            line = next(content)

        while 'END OF INPUT FILE FOR BADER' not in line:
github cclib / cclib / test / io / testmoldenwriter.py View on Github external
def test_molden_cclib_diff(self):
        """Check if file written by cclib matched file written by Molden."""
        filenames = ['dvb_un_sp', 'C_bigbasis', 'water_mp2']
        for fn in filenames:
            fpath = os.path.join(__datadir__,
                                 "data/GAMESS/basicGAMESS-US2018/"+fn+".out")
            data = cclib.io.ccread(fpath)
            cclib_out = cclib.io.moldenwriter.MOLDEN(data).generate_repr()
            # Reformat cclib's output to remove extra spaces.
            cclib_out_formatted = MoldenReformatter(cclib_out).reformat()
            fpath = os.path.join(__testdir__, "data/molden5.7_"+fn+".molden")
            with open(fpath) as handle:
                molden_out = handle.read()
            # Reformat Molden's output to remove extra spaces,
            # and fix number formatting.
            molden_out_formatted = MoldenReformatter(molden_out).reformat()
            # Assert if reformatted files from both writers are same.
            self.assertMultiLineEqual(molden_out_formatted,
                                      cclib_out_formatted)
github cclib / cclib / test / io / testwfxwriter.py View on Github external
def test_no_of_prims(self):
        """Check if number of primitives are calculated correctly."""
        num_orb = {'s':1, 'p':3, 'd':6, 'f':10, 'g':15, 'h':21}
        gamessdir = os.path.join(__datadir__,
                                 "data/GAMESS/basicGAMESS-US2017")
        filenames = ["C_bigbasis.out", "dvb_un_sp.out"]
        filepaths = [os.path.join(gamessdir, fn) for fn in filenames]

        for fpath in filepaths:
            data = cclib.io.ccread(fpath)
            wfx = cclib.io.wfxwriter.WFXWriter(data)

            no_prims_writer = wfx._no_of_prims()
            no_prims_ccdata = 0
            for atom in data.gbasis:
                for prims in atom:
                    no_prims_ccdata += num_orb[prims[0].lower()]\
                                        * len(prims[1])

            self.assertEqual(no_prims_writer, no_prims_ccdata)
github cclib / cclib / cclib / scripts / ccget.py View on Github external
# passing options downstream. For example, we might use --future for
        # triggering experimental or alternative behavior (as with optdone).
        kwargs = {}
        if verbose:
            kwargs['verbose'] = True
            kwargs['loglevel'] = logging.INFO
        else:
            kwargs['verbose'] = False
            kwargs['loglevel'] = logging.ERROR
        if future:
            kwargs['future'] = True
        if cjsonfile:
            kwargs['cjson'] = True

        print("Attempting to read %s" % name)
        data = ccread(filename, **kwargs)

        if data == None:
            print("Cannot figure out the format of '%s'" % name)
            print("Report this to the cclib development team if you think it is an error.")
            print("\n" + MSG_USAGE)
            sys.exit()

        if showattr:
            print("cclib can parse the following attributes from %s:" % name)
            if cjsonfile:
                for key in data:
                    print(key)
                break
            for attr in data._attrlist:
                if hasattr(data, attr):
                    print("  %s" % attr)
github cclib / cclib / cclib / scripts / cda.py View on Github external
def main():
    parser = ArgumentParser()
    parser.add_argument("file1", help="logfile containing the supermolecule")
    parser.add_argument("file2", help="logfile containing the first fragment")
    parser.add_argument("file3", help="logfile containing the second fragment")
    args = parser.parse_args()

    loglevel = logging.ERROR

    data1 = ccread(args.file1, loglevel=loglevel)
    data2 = ccread(args.file2, loglevel=loglevel)
    data3 = ccread(args.file3, loglevel=loglevel)

    fa = CDA(data1, None, loglevel)
    retval = fa.calculate([data2, data3])

    if retval:

        print("Charge decomposition analysis of {}\n".format(args.file1))

        if len(data1.homos) == 2:
            print("ALPHA SPIN:")
            print("===========")

        print(" MO#      d       b       r       s")
        print("-------------------------------------")