コード例 #1
0
ファイル: dbtest.py プロジェクト: gkalab/ChessCore
def main():
    common.parser().add_option("--indb", dest="indb", help="Input database")

    if not common.init(__file__):
        exit(2)

    progname = common.progname()
    indb = common.options().indb
    if not indb:
        indb = common.testdir() + "/pgn/Kramnik.pgn"
    temppgn1 = common.tmpdir() + "/copydb1.pgn"
    temppgn2 = common.tmpdir() + "/copydb2.pgn"
    tempcfdb1 = common.tmpdir() + "/copydb1.cfdb"

    if run(1, indb, tempcfdb1) and run(2, tempcfdb1, temppgn1) and run(3, indb, temppgn2):
        # temppgn1 and temppgn2 should be identical
        if os.path.exists(temppgn1) and os.path.exists(temppgn2):
            lines1 = open(temppgn1, "U").readlines()
            lines2 = open(temppgn2, "U").readlines()
            diff = difflib.unified_diff(lines1, lines2)
            different = False
            first = True
            for line in diff:
                if first:
                    print "{0}: PGN files {1} and {2} are different:".format(progname, temppgn1, temppgn2)
                    different = True
                    first = False
                print line
            if not different:
                print "{0}: Test successful".format(progname)
        else:
            print "{0}: Failed; no output files to compare".format(progname)
コード例 #2
0
ファイル: classify.py プロジェクト: jeremybernstein/ChessCore
def main():
    common.parser().add_option("--indb", dest = "indb", help = "Input database")
    common.parser().add_option("--outdb", dest = "outdb", help = "Output database")
    common.parser().add_option("--firstgame", dest="firstgame", help = "First game in input database to analyze")
    common.parser().add_option("--lastgame", dest="lastgame",help = "First game in input database to analyze")
    common.parser().add_option("--ecofile", dest = "ecofile", help = "The (.cfdb) database containing the ECO classification")

    if not common.init(__file__):
        exit(2)

    progname = common.progname()
    debuglog = True
    logcomms = False
    logfile1 = common.tmpdir() + "/ccore1.log"
    logfile2 = common.tmpdir() + "/ccore2.log"
    configfile = common.configfile()
    indb = common.options().indb
    if not indb:
        indb = common.testdir() + "/pgn/Boris_Spassky.pgn"
    outdb = common.options().outdb
    if not outdb:
        outdb = common.tmpdir() + "/classified.cfdb"
        if os.path.exists(outdb):
            os.remove(outdb)
    ecofile = common.options().ecofile
    if not ecofile:
        ecofile = common.testdir() + "/cfdb/eco.cfdb"
    firstgame = common.options().firstgame
    lastgame = common.options().lastgame

    if os.path.exists(logfile1):
        os.remove(logfile1)
    if os.path.exists(logfile2):
        os.remove(logfile2)

    # Take a copy of the database
    cmdline = common.ccore()
    if debuglog:
        cmdline += " --debuglog true"
    if logcomms:
        cmdline += " --logcomms true"
    if firstgame:
        cmdline += " -n {0}".format(firstgame)
    if lastgame:
        cmdline += " -N {0}".format(lastgame)
    cmdline += " -l {0} -i {1} -o {2} copydb".format(logfile1, indb, outdb);
    if common.runccore(cmdline):
        common.checkLogfile(logfile1)

        # And then classify the copy
        cmdline = common.ccore()
        if debuglog:
            cmdline += " --debuglog true"
        if logcomms:
            cmdline += " --logcomms true"
        cmdline += " -l {0} -i {1} -E {2} classify".format(logfile2, outdb, ecofile)
        if common.runccore(cmdline):
            common.checkLogfile(logfile2)
コード例 #3
0
ファイル: epd.py プロジェクト: gkalab/ChessCore
def main():
    common.parser().add_option("--epdfile", dest = "epdfile", help = "Input EPD file")
    common.parser().add_option("--timecontrol", dest="timecontrol", default = "10s", help = "Time control")
    common.parser().add_option("--engine", dest="engine", help = "The engine to use to process the EPD file")

    if not common.init(__file__):
        exit(2)

    progname = common.progname()
    debuglog = True
    logcomms = False
    logfile = common.tmpdir() + "/ccore.log"
    configfile = common.configfile()
    epdfile = common.options().epdfile
    if not epdfile:
        usage()
    timecontrol = common.options().timecontrol
    engine = common.options().engine
    if not engine:
        engine = common.engine1()

    if os.path.exists(logfile):
        os.remove(logfile)

    # Take a copy of the database
    cmdline = common.ccore()
    if debuglog:
        cmdline += " --debuglog true"
    if logcomms:
        cmdline += " --logcomms true"
    cmdline += " -c {0} -l {1} -e {2} -t {3} processepd {4}".format(configfile, logfile, epdfile, timecontrol, engine);
    if common.runccore(cmdline):
        common.checkLogfile(logfile)
コード例 #4
0
ファイル: test_examples.py プロジェクト: molmod/QuickFF
def test_uio66zrbrick_crossterms():
    with log.section('NOSETEST', 2):
        # Load input data for a ficticious system of an isolated
        # UiO-66 brick
        name = 'uio66-zr-brick/system.chk'
        fn = context.get_fn(os.path.join('systems', name))
        data = load_chk(fn)
        system = System(data['numbers'],data['pos'],charges=data['charges'],
            ffatypes=data['ffatypes'],bonds=data['bonds'],radii=data['radii'])
        system.set_standard_masses()
        ai = SecondOrderTaylor('ai', coords=system.pos.copy(),
             grad=data['gradient'], hess=data['hessian'])
        # Run QuickFF
        with tmpdir('test_uio66') as dn:
            fn_yaff = os.path.join(dn, 'pars_cov.txt')
            fn_sys = os.path.join(dn, 'system.chk')
            fn_log = os.path.join(dn, 'quickff.log')
            program = DeriveFF(system, ai, Settings(consistent_cross_rvs=True,
                remove_dysfunctional_cross=True,fn_yaff=fn_yaff,fn_sys=fn_sys,log_file=fn_log))
            program.run()
        # Check force constants of cross terms and corresponding diagonal terms
        print("%50s %15s %15s"%("Basename","Cross FC","Diag FC"))
        for term in program.valence.terms:
            if not term.is_master(): continue
            if term.basename.startswith('Cross'):
                fc = program.valence.get_params(term.index, only='fc')
                for i in [0,1]:
                    fc_diag = program.valence.get_params(term.diag_term_indexes[i], only='fc')
                    print("%50s %15.6f %15.6f %50s" % (term.basename,fc,fc_diag,program.valence.terms[term.diag_term_indexes[i]].basename))
                    if fc_diag==0.0: assert fc==0.0
コード例 #5
0
ファイル: create_eco.py プロジェクト: gkalab/ChessCore
def main():
    common.parser().add_option("--indb", dest = "indb", help = "Input database")
    common.parser().add_option("--outdb", dest = "outdb", help = "Output database")
    
    if not common.init(__file__):
        exit(2)

    progname = common.progname()
    debuglog = True
    logfile1 = common.tmpdir() + "/ccore1.log"
    logfile2 = common.tmpdir() + "/ccore2.log"
    indb = common.options().indb
    if not indb:
        indb = common.rootdir() + "/doc/OpeningClassification/eco.pgn"
    outdb = common.options().outdb
    if not outdb:
        outdb = common.testdir() + "/cfdb/eco.cfdb"

    if os.path.exists(logfile1):
        os.remove(logfile1)
    if os.path.exists(logfile2):
        os.remove(logfile2)
    if os.path.exists(outdb):
        os.remove(outdb)

    # Copy the database
    cmdline = common.ccore()
    if debuglog:
        cmdline += " --debuglog true"

    cmdline += " -l {0} -i {1} -o {2} copydb".format(logfile1, indb, outdb)
    if common.runccore(cmdline):
        common.checkLogfile(logfile1)

        # Create the opening tree in the output database
        cmdline = common.ccore()
        if debuglog:
            cmdline += " --debuglog true"
        cmdline += " -l {0} -i {1} -d 100 buildoptree".format(logfile2, outdb)
        if common.runccore(cmdline):
            common.checkLogfile(logfile2)
コード例 #6
0
ファイル: tournament.py プロジェクト: gkalab/ChessCore
def main():
    common.parser().add_option("--engine1", dest = "engine1", help = "Engine #1")
    common.parser().add_option("--engine2", dest = "engine2", help = "Engine #2")
    common.parser().add_option("--numgames", dest = "numgames", type = "int", default = 5, help = "Number of games")
    common.parser().add_option("--timecontrol", dest = "timecontrol", default = "30", help = "Time control")
    common.parser().add_option("--ecofile", dest = "ecofile", help = "The (.cfdb) database containing the ECO classification")
    common.parser().add_option("--logcomms", dest = "logcomms", type = "int", default = 0, help = "Log UCI comms")

    if not common.init(__file__):
        exit(2)

    progname = common.progname()
    debuglog = True
    logcomms = common.options().logcomms != 0
    logfile = common.tmpdir() + "/ccore.log"
    pgnfile = common.tmpdir() + "/games.pgn"
    configfile = common.configfile()
    ecofile = common.options().ecofile
    if not ecofile:
        ecofile = common.testdir() + "/cfdb/eco.cfdb"
    engine1 = common.options().engine1
    if not engine1:
        engine1 = common.engine1()
    engine2 = common.options().engine2
    if not engine2:
        engine2 = common.engine2()
    numgames = common.options().numgames
    timecontrol = common.options().timecontrol

    if os.path.exists(logfile):
        os.remove(logfile)

    cmdline = common.ccore()
    if debuglog:
        cmdline += " --debuglog true"
    if logcomms:
        cmdline += " --logcomms true"
    cmdline += " -c {0} -l {1} -o {2} -E {3} -n {4} -t {5} tournament {6} {7}".format(configfile, logfile, pgnfile, ecofile, numgames, timecontrol, engine1, engine2)
    if common.runccore(cmdline):
        common.checkLogfile(logfile)
コード例 #7
0
ファイル: test_examples.py プロジェクト: molmod/QuickFF
def test_methane_consistent_crossterms():
    with log.section('NOSETEST', 2):
        system, ai = read_system('methane/gaussian.fchk')
        set_ffatypes(system, 'high')
        for consistent in [False, True]:
            with tmpdir('test_methane_%s'%('consistent' if consistent else 'inconsistent')) as dn:
                fn_yaff = os.path.join(dn, 'pars_cov.txt')
                fn_sys = os.path.join(dn, 'system.chk')
                program = DeriveFF(system, ai, Settings(consistent_cross_rvs=consistent,
                    fn_yaff=fn_yaff,fn_sys=fn_sys,do_cross_DSS=True,do_cross_DSD=True,
                        do_cross_DAA=True,do_cross_DAD=True))
                program.run()
                compare_crossterm_rest_values(program,equal=consistent)
コード例 #8
0
ファイル: test_examples.py プロジェクト: riddlezyc/QuickFF
def test_uio66zrbrick_crossterms():
    with log.section('NOSETEST', 2):
        # Load input data for a ficticious system of an isolated
        # UiO-66 brick
        name = 'uio66-zr-brick/system.chk'
        fn = context.get_fn(os.path.join('systems', name))
        data = load_chk(fn)
        system = System(data['numbers'],
                        data['pos'],
                        charges=data['charges'],
                        ffatypes=data['ffatypes'],
                        bonds=data['bonds'],
                        radii=data['radii'])
        system.set_standard_masses()
        ai = SecondOrderTaylor('ai',
                               coords=system.pos.copy(),
                               grad=data['gradient'],
                               hess=data['hessian'])
        # Run QuickFF
        with tmpdir('test_uio66') as dn:
            fn_yaff = os.path.join(dn, 'pars_cov.txt')
            fn_sys = os.path.join(dn, 'system.chk')
            fn_log = os.path.join(dn, 'quickff.log')
            program = DeriveFF(
                system, ai,
                Settings(consistent_cross_rvs=True,
                         remove_dysfunctional_cross=True,
                         fn_yaff=fn_yaff,
                         fn_sys=fn_sys,
                         log_file=fn_log))
            program.run()
        # Check force constants of cross terms and corresponding diagonal terms
        print("%50s %15s %15s" % ("Basename", "Cross FC", "Diag FC"))
        for term in program.valence.terms:
            if not term.is_master(): continue
            if term.basename.startswith('Cross'):
                fc = program.valence.get_params(term.index, only='fc')
                for i in [0, 1]:
                    fc_diag = program.valence.get_params(
                        term.diag_term_indexes[i], only='fc')
                    print("%50s %15.6f %15.6f %50s" %
                          (term.basename, fc, fc_diag, program.valence.terms[
                              term.diag_term_indexes[i]].basename))
                    if fc_diag == 0.0: assert fc == 0.0
コード例 #9
0
ファイル: skip_js_compile.py プロジェクト: zennsocial/skip
def compile(stack, args):
    extraOpts = []
    skip_flags = os.environ.get('SKIP_FLAGS', '')
    if skip_flags:
        extraOpts += skip_flags.split(',')

    output = stack.enter_context(common.tmpdir(prefix='tmp.js_exec.'))
    cmd = [
        os.path.join(common.build_dir, 'bin/skip_to_js'), '--output',
        output + '/sk.js', '--no-source-map'
    ] + extraOpts + args.srcs

    logger.debug('Running: ' + ' '.join(map(pipes.quote, cmd)))

    with common.PerfTimer('skip_to_js.runtime'):
        common.callHelper(cmd)

    return [
        common.root_dir + '/tools/run_js', '--no-unhandled-exception-stack',
        output
    ]
コード例 #10
0
ファイル: test_examples.py プロジェクト: riddlezyc/QuickFF
def test_methane_consistent_crossterms():
    with log.section('NOSETEST', 2):
        system, ai = read_system('methane/gaussian.fchk')
        set_ffatypes(system, 'high')
        for consistent in [False, True]:
            with tmpdir(
                    'test_methane_%s' %
                ('consistent' if consistent else 'inconsistent')) as dn:
                fn_yaff = os.path.join(dn, 'pars_cov.txt')
                fn_sys = os.path.join(dn, 'system.chk')
                program = DeriveFF(
                    system, ai,
                    Settings(consistent_cross_rvs=consistent,
                             fn_yaff=fn_yaff,
                             fn_sys=fn_sys,
                             do_cross_DSS=True,
                             do_cross_DSD=True,
                             do_cross_DAA=True,
                             do_cross_DAD=True))
                program.run()
                compare_crossterm_rest_values(program, equal=consistent)
コード例 #11
0
def test_output_charmm22():
    with log.section('NOSETST', 2):
        system, ai = read_system('ethanol/gaussian.fchk')
        set_ffatypes(system, 'low')
        with tmpdir('test_output_charmm22') as dn:
            fn_yaff = os.path.join(dn, 'pars_cov.txt')
            fn_charmm22_prm = os.path.join(dn, 'test.prm')
            fn_charmm22_psf = os.path.join(dn, 'test.psf')
            fn_sys = os.path.join(dn, 'system.chk')
            settings = Settings(
                do_cross_ASS=False, do_cross_ASA=False,
                fn_yaff=fn_yaff, fn_sys=fn_sys,
                fn_charmm22_prm=fn_charmm22_prm,
                fn_charmm22_psf=fn_charmm22_psf,
            )
            program = DeriveFF(system, ai, settings)
            program.run()
            assert os.path.isfile(fn_yaff)
            assert os.path.isfile(fn_charmm22_prm)
            assert os.path.isfile(fn_charmm22_psf)
            assert os.path.isfile(fn_sys)

            # Count the number of BOND, ANGLES and DIHEDRAL lines in the PRM file.
            counts = {}
            with open(fn_charmm22_prm, 'r') as f:
                for line in f:
                    print line
                    line = line[:line.find('!')].strip()
                    if len(line) == 0:
                        continue
                    if line in ['BONDS','ANGLES', 'DIHEDRALS', 'IMPROPER']:
                        key = line
                        counts[key] = 0
                    else:
                        counts[key] += 1
            assert counts['BONDS'] == 4
            assert counts['ANGLES'] == 5
            assert counts['DIHEDRALS'] == 2
            assert counts['IMPROPER'] == 0

            # Count the number atoms, bonds, angles and dihedrals in the PSF file and
            # check for consistency.
            with open(fn_charmm22_psf, 'r') as f:
                natom = 0
                assert f.next() == 'PSF\n'
                for line in f:
                    if '!NATOM' in line:
                        natom = int(line.split()[0])
                        break
                assert natom == system.natom
                for iatom in xrange(natom+1):
                    f.next()
                line = f.next()
                assert '!NBOND: bonds' in line
                nbond = int(line.split()[0])
                nline = int(np.ceil(nbond/4.0))
                numbers = (''.join([f.next() for iline in xrange(nline)])).split()
                assert len(numbers) == nbond*2
                f.next()
                line = f.next()
                assert '!NTHETA: angles' in line
                ntheta = int(line.split()[0])
                nline = int(np.ceil(ntheta/3.0))
                numbers = (''.join([f.next() for iline in xrange(nline)])).split()
                assert len(numbers) == ntheta*3
                f.next()
                line = f.next()
                assert '!NPHI: dihedrals' in line
                nphi = int(line.split()[0])
                nline = int(np.ceil(nphi/2.0))
                numbers = (''.join([f.next() for iline in xrange(nline)])).split()
                assert len(numbers) == nphi*4
                f.next()
                line = f.next()
                assert '!NIMPHI: impropers' in line
                nimphi = int(line.split()[0])
                assert nimphi == 0
コード例 #12
0
ファイル: dbtest.py プロジェクト: gkalab/ChessCore
def run(runcycle, indb, outdb):
    progname = common.progname()
    logfile1 = common.tmpdir() + "/copy" + str(runcycle) + ".log"
    logfile2 = common.tmpdir() + "/validate" + str(runcycle) + ".log"
    if not os.path.exists(indb):
        print "{0}: Input database {1} does not exist".format(progname, indb)
        return False
    if os.path.exists(logfile1):
        os.remove(logfile1)
    if os.path.exists(logfile2):
        os.remove(logfile2)
    if os.path.exists(outdb):
        os.remove(outdb)

    print "========================================================================================"
    print "{0}: Copying {1} to {2}".format(progname, indb, outdb)

    cmdline = common.ccore()
    cmdline += " -l {0} -i {1} -o {2} --quiet=true --debuglog=true copydb".format(logfile1, indb, outdb)
    if not common.runccore(cmdline):
        return False

    common.checkLogfile(logfile1)

    # Check that the copy was successful
    found = False
    f = open(logfile1, "r")
    for line in f:
        if re.search("Successfully copied database", line):
            found = True
            break
    if found:
        print "{0}: Copy successful".format(progname)
    else:
        print "{0}: Copy failed".format(progname)
        return False

    print "----------------------------------------------------------------------------------------"
    print "{0}: Validating {1}".format(progname, outdb)

    cmdline = common.ccore()
    cmdline += " -l {0} -i {1} --quiet true --debuglog true validatedb".format(logfile2, outdb)
    if not common.runccore(cmdline):
        return False

    common.checkLogfile(logfile2)

    # Check that the validate was successful
    found = False
    f = open(logfile2, "r")
    for line in f:
        if re.search("Database is valid", line):
            found = True
            break
    if found:
        print "{0}: Validate successful".format(progname)
    else:
        print "{0}: Validate failed".format(progname)
        return False

    return True
コード例 #13
0
ファイル: test_examples.py プロジェクト: molmod/QuickFF
def test_output_charmm22():
    with log.section('NOSETST', 2):
        system, ai = read_system('ethanol/gaussian.fchk')
        set_ffatypes(system, 'low')
        with tmpdir('test_output_charmm22') as dn:
            fn_yaff = os.path.join(dn, 'pars_cov.txt')
            fn_charmm22_prm = os.path.join(dn, 'test.prm')
            fn_charmm22_psf = os.path.join(dn, 'test.psf')
            fn_sys = os.path.join(dn, 'system.chk')
            settings = Settings(
                do_cross_ASS=False, do_cross_ASA=False,
                fn_yaff=fn_yaff, fn_sys=fn_sys,
                fn_charmm22_prm=fn_charmm22_prm,
                fn_charmm22_psf=fn_charmm22_psf,
            )
            program = DeriveFF(system, ai, settings)
            program.run()
            assert os.path.isfile(fn_yaff)
            assert os.path.isfile(fn_charmm22_prm)
            assert os.path.isfile(fn_charmm22_psf)
            assert os.path.isfile(fn_sys)

            # Count the number of BOND, ANGLES and DIHEDRAL lines in the PRM file.
            counts = {}
            with open(fn_charmm22_prm, 'r') as f:
                for line in f:
                    print(line)
                    line = line[:line.find('!')].strip()
                    if len(line) == 0:
                        continue
                    if line in ['BONDS','ANGLES', 'DIHEDRALS', 'IMPROPER']:
                        key = line
                        counts[key] = 0
                    else:
                        counts[key] += 1
            assert counts['BONDS'] == 4
            assert counts['ANGLES'] == 5
            assert counts['DIHEDRALS'] == 3
            assert counts['IMPROPER'] == 0

            # Count the number atoms, bonds, angles and dihedrals in the PSF file and
            # check for consistency.
            with open(fn_charmm22_psf, 'r') as f:
                natom = 0
                assert next(f) == 'PSF\n'
                for line in f:
                    if '!NATOM' in line:
                        natom = int(line.split()[0])
                        break
                assert natom == system.natom
                for iatom in range(natom+1):
                    next(f)
                line = next(f)
                assert '!NBOND: bonds' in line
                nbond = int(line.split()[0])
                nline = int(np.ceil(nbond/4.0))
                numbers = (''.join([next(f) for iline in range(nline)])).split()
                assert len(numbers) == nbond*2
                next(f)
                line = next(f)
                assert '!NTHETA: angles' in line
                ntheta = int(line.split()[0])
                nline = int(np.ceil(ntheta/3.0))
                numbers = (''.join([next(f) for iline in range(nline)])).split()
                assert len(numbers) == ntheta*3
                next(f)
                line = next(f)
                assert '!NPHI: dihedrals' in line
                nphi = int(line.split()[0])
                nline = int(np.ceil(nphi/2.0))
                numbers = (''.join([next(f) for iline in range(nline)])).split()
                assert len(numbers) == nphi*4
                next(f)
                line = next(f)
                assert '!NIMPHI: impropers' in line
                nimphi = int(line.split()[0])
                assert nimphi == 0