def from_string(cls, contents):
        """
        Creates QcInput from a string.

        Args:
            contents: String representing a QChem input file.

        Returns:
            QcInput object
        """
        mol = None
        charge = None
        spin_multiplicity = None
        params = dict()
        lines = contents.split('\n')
        parse_section = False
        section_name = None
        section_text = []
        ghost_atoms = None
        for line_num, line in enumerate(lines):
            l = line.strip().lower()

            if len(l) == 0:
                continue
            if (not parse_section) and (l == "$end" or not l.startswith("$")):
                raise ValueError("Format error, parsing failed")
            if parse_section and l != "$end":
                section_text.append(line)
            if l.startswith("$") and not parse_section:
                parse_section = True
                section_name = l[1:]
                available_sections = ["comment", "molecule", "rem"] + \
                    sorted(list(cls.optional_keywords_list))
                if section_name not in available_sections:
                    raise ValueError("Unrecognized keyword " + line.strip() +
                                     " at line " + str(line_num))
                if section_name in params:
                    raise ValueError("duplicated keyword " + line.strip() +
                                     "at line " + str(line_num))
            if parse_section and l == "$end":
                func_name = "_parse_" + section_name
                if func_name not in QcTask.__dict__:
                    raise Exception(func_name + " is not implemented yet, "
                                    "please implement it")
                parse_func = QcTask.__dict__[func_name].__get__(None, QcTask)
                if section_name == "molecule":
                    mol, charge, spin_multiplicity, ghost_atoms = parse_func(section_text)
                else:
                    d = parse_func(section_text)
                    params[section_name] = d
                parse_section = False
                section_name = None
                section_text = []
        if parse_section:
            raise ValueError("Format error. " + section_name + " is not "
                             "terminated")
        jobtype = params["rem"]["jobtype"]
        title = params.get("comment", None)
        exchange = params["rem"].get("exchange", "hf")
        method = params["rem"].get("method", None)
        correlation = params["rem"].get("correlation", None)
        basis_set = params["rem"]["basis"]
        aux_basis_set = params["rem"].get("aux_basis", None)
        ecp = params["rem"].get("ecp", None)
        optional_params = None
        op_keys = set(params.keys()) - {"comment", "rem"}
        if len(op_keys) > 0:
            optional_params = dict()
            for k in op_keys:
                optional_params[k] = params[k]
        return QcTask(molecule=mol, charge=charge,
                      spin_multiplicity=spin_multiplicity,
                      jobtype=jobtype, title=title,
                      exchange=exchange, correlation=correlation,
                      basis_set=basis_set, aux_basis_set=aux_basis_set,
                      ecp=ecp, rem_params=params["rem"],
                      optional_params=optional_params,
                      ghost_atoms=ghost_atoms,
                      method=method)
def from_string ( cls , contents ) : mol = None charge = None spin_multiplicity = None params = dict ( ) lines = contents . split ( '\n' ) parse_section = False section_name = None section_text = [ ] ghost_atoms = None for line_num , line in enumerate ( lines ) : l = line . strip ( ) . lower ( ) if len ( l ) == 0 : continue if ( not parse_section ) and ( l == "$end" or not l . startswith ( "$" ) ) : raise ValueError ( "Format error, parsing failed" ) if parse_section and l != "$end" : section_text . append ( line ) if l . startswith ( "$" ) and not parse_section : parse_section = True section_name = l [ 1 : ] available_sections = [ "comment" , "molecule" , "rem" ] + sorted ( list ( cls . optional_keywords_list ) ) if section_name not in available_sections : raise ValueError ( "Unrecognized keyword " + line . strip ( ) + " at line " + str ( line_num ) ) if section_name in params : raise ValueError ( "duplicated keyword " + line . strip ( ) + "at line " + str ( line_num ) ) if parse_section and l == "$end" : func_name = "_parse_" + section_name if func_name not in QcTask . __dict__ : raise Exception ( func_name + " is not implemented yet, " "please implement it" ) parse_func = QcTask . __dict__ [ func_name ] . __get__ ( None , QcTask ) if section_name == "molecule" : mol , charge , spin_multiplicity , ghost_atoms = parse_func ( section_text ) else : d = parse_func ( section_text ) params [ section_name ] = d parse_section = False section_name = None section_text = [ ] if parse_section : raise ValueError ( "Format error. " + section_name + " is not " "terminated" ) jobtype = params [ "rem" ] [ "jobtype" ] title = params . get ( "comment" , None ) exchange = params [ "rem" ] . get ( "exchange" , "hf" ) method = params [ "rem" ] . get ( "method" , None ) correlation = params [ "rem" ] . get ( "correlation" , None ) basis_set = params [ "rem" ] [ "basis" ] aux_basis_set = params [ "rem" ] . get ( "aux_basis" , None ) ecp = params [ "rem" ] . get ( "ecp" , None ) optional_params = None op_keys = set ( params . keys ( ) ) - { "comment" , "rem" } if len ( op_keys ) > 0 : optional_params = dict ( ) for k in op_keys : optional_params [ k ] = params [ k ] return QcTask ( molecule = mol , charge = charge , spin_multiplicity = spin_multiplicity , jobtype = jobtype , title = title , exchange = exchange , correlation = correlation , basis_set = basis_set , aux_basis_set = aux_basis_set , ecp = ecp , rem_params = params [ "rem" ] , optional_params = optional_params , ghost_atoms = ghost_atoms , method = method )
Creates QcInput from a string.

        Args:
            contents: String representing a QChem input file.

        Returns:
            QcInput object