How to use the signac.get_project function in signac

To help you get started, we’ve selected a few signac 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 glotzerlab / signac / tests / test_shell.py View on Github external
def test_project_id(self):
        self.call('python -m signac init my_project'.split())
        assert str(signac.get_project()) == 'my_project'
        assert self.call('python -m signac project'.split()).strip() == 'my_project'
github glotzerlab / signac / tests / test_shell.py View on Github external
def test_init_project_in_project_root(self):
        self.call('python -m signac init my_project'.split())
        assert str(signac.get_project()) == 'my_project'
        with pytest.raises(ExitCodeError):
            self.call('python -m signac init second_project'.split())
github glotzerlab / signac / tests / test_project.py View on Github external
def test_nested_project(self):
        def check_root(root=None):
            if root is None:
                root = os.getcwd()
            assert os.path.realpath(signac.get_project(root=root).root_directory()) == \
                os.path.realpath(root)
        root = self._tmp_dir.name
        root_a = os.path.join(root, 'project_a')
        root_b = os.path.join(root_a, 'project_b')
        signac.init_project('testprojectA', root_a)
        assert signac.get_project(root=root_a).id == 'testprojectA'
        check_root(root_a)
        signac.init_project('testprojectB', root_b)
        assert signac.get_project(root=root_b).id == 'testprojectB'
        check_root(root_b)
        cwd = os.getcwd()
        try:
            os.chdir(root_a)
            check_root()
            assert signac.get_project().id == 'testprojectA'
        finally:
            os.chdir(cwd)
        try:
            os.chdir(root_b)
            assert signac.get_project().id == 'testprojectB'
            check_root()
        finally:
github glotzerlab / signac / tests / test_project.py View on Github external
def check_root(root=None):
            if root is None:
                root = os.getcwd()
            assert os.path.realpath(signac.get_project(root=root).root_directory()) == \
                os.path.realpath(root)
        root = self._tmp_dir.name
github glotzerlab / signac / examples / ideal_gas_project / init.py View on Github external
# init.py
import signac
import numpy as np

project = signac.get_project()
#for pressure in 0.1, 1.0, 10.0:
for pressure in np.linspace(0.1, 10.0, 10):
    statepoint = {'p': pressure, 'kT': 1.0, 'N': 1000}
    job = project.open_job(statepoint)
    job.init()
    print(job, 'initialized')
github glotzerlab / signac / examples / ideal_gas_project_only_files / project.py View on Github external
# project.py
import signac

def classify(job):
    yield 'init'
    if job.isfile('V.txt'):
        yield 'volume-computed'

def next_operation(job):
    if 'volume-computed' not in classify(job):
        return 'compute_volume'

if __name__ == '__main__':
    project = signac.get_project()
    print(project)

    for job in project.find_jobs():
        labels = ','.join(classify(job))
        p = '{:04.1f}'.format(job.statepoint()['p'])
        print(job, p, labels)
github glotzerlab / signac / examples / ideal_gas_project_only_files / examine.py View on Github external
# examine.py
import os
import signac

def get_volume(job):
    "Return the computed volume for this job."
    with open(job.fn('V.txt')) as file:
        return float(file.read())

project = signac.get_project()

print('p    V')
for job in project.find_jobs():
    p = job.statepoint()['p']
    V = get_volume(job)
    print('{:04.1f} {}'.format(p, V))
github glotzerlab / signac / signac / __main__.py View on Github external
def main_shell(args):
    if args.file and args.command:
        raise ValueError(
            "Cannot provide file and -c/--command argument at the same time!")

    try:
        project = get_project()
    except LookupError:
        print("signac", __version__)
        print("No project within this directory.")
        print("If you want to initialize a project, execute `$ signac init `, "
              "where  can be freely chosen.")
    else:
        _jobs = find_with_filter(args)

        def jobs():
            for _id in _jobs:
                yield project.open_job(id=_id)

        if len(_jobs) == 1:
            job = _open_job_by_id(project, list(_jobs)[0])
        else:
            try:
github glotzerlab / signac-dashboard / examples / plots / init.py View on Github external
#!/usr/bin/env python3
# Copyright (c) 2018 The Regents of the University of Michigan
# All rights reserved.
# This software is licensed under the BSD 3-Clause License.
import signac
import numpy as np
import matplotlib
# Force matplotlib to not use any Xwindows backend.
matplotlib.use('Agg')
import matplotlib.pyplot as plt  # noqa: E402

try:
    project = signac.get_project()
except LookupError:
    project = signac.init_project('plots')


def plot_coherence(job):
    # Plot script adapted from:
    # https://matplotlib.org/gallery/lines_bars_and_markers/cohere.html

    print('Making plots for coherence time {}, job {}'.format(
        job.sp.coherence_time, job))
    # Fixing random state for reproducibility
    np.random.seed(job.sp.seed)

    dt = 0.01
    t = np.arange(0, 30, dt)
    nse1 = np.random.randn(len(t))                 # white noise 1
github glotzerlab / signac / signac / __main__.py View on Github external
def main_remove(args):
    project = get_project()
    for job_id in args.job_id:
        job = _open_job_by_id(project, job_id)
        if args.interactive and not query_yes_no(
            "Are you sure you want to {action} job with id '{job._id}'?".format(
                action='clear' if args.clear else 'remove',
                job=job), default='no'):
            continue
        if args.clear:
            job.clear()
        else:
            job.remove()
        if args.verbose:
            print(job_id)