Skip to content

Commit

Permalink
Advancing the migration to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha committed Nov 28, 2019
1 parent bd80305 commit b9ea033
Show file tree
Hide file tree
Showing 29 changed files with 294 additions and 219 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

@pytest.fixture(scope='function')
def raspa_code(aiida_local_code_factory): # pylint: disable=unused-argument
return aiida_local_code_factory("simulate", "raspa")
return aiida_local_code_factory("raspa", "simulate")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def example_base(raspa_code, submit=True):
})

# framework
framework = CifData(file=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'files', 'TCC1RS.cif'))
framework = CifData(file=os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'files', 'TCC1RS.cif'))

# Contructing builder
builder = raspa_code.get_builder()
Expand Down Expand Up @@ -90,14 +90,15 @@ def example_base(raspa_code, submit=True):

@click.command('cli')
@click.argument('codelabel')
def cli(codelabel):
@click.option('--submit', is_flag=True, help='Actually submit calculation')
def cli(codelabel, submit):
"""Click interface"""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist".format(codelabel))
sys.exit(1)
example_base(code)
example_base(code, submit)


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@
CifData = DataFactory('cif') # pylint: disable=invalid-name


@click.command('cli')
@click.argument('codelabel')
@click.option('--previous_calc', '-p', required=True, type=int, help='PK of test_raspa_base.py calculation')
@click.option('--submit', is_flag=True, help='Actually submit calculation')
def main(codelabel, previous_calc, submit):
def example_base_restart(raspa_code, previous_calc, submit=True):
"""Prepare and submit restart from simple RASPA calculation."""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist".format(codelabel))
sys.exit(1)

# parameters
parameters = Dict(
Expand Down Expand Up @@ -62,13 +53,13 @@ def main(codelabel, previous_calc, submit):
})

# framework
framework = CifData(file=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'files', 'TCC1RS.cif'))
framework = CifData(file=os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'files', 'TCC1RS.cif'))

# restart file
retrieved_parent_folder = load_node(previous_calc).outputs.retrieved

# Contructing builder
builder = code.get_builder()
builder = raspa_code.get_builder()
builder.framework = {
"tcc1rs": framework,
}
Expand Down Expand Up @@ -101,7 +92,21 @@ def main(codelabel, previous_calc, submit):
print("-----")


@click.command('cli')
@click.argument('codelabel')
@click.option('--previous_calc', '-p', required=True, type=int, help='PK of example_base.py calculation')
@click.option('--submit', is_flag=True, help='Actually submit calculation')
def cli(codelabel, previous_calc, submit):
"""Click interface"""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist".format(codelabel))
sys.exit(1)
example_base_restart(code, previous_calc, submit)


if __name__ == '__main__':
main() # pylint: disable=no-value-for-parameter
cli() # pylint: disable=no-value-for-parameter

# EOF
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,8 @@
from aiida.orm import Code, Dict


@click.command('cli')
@click.argument('codelabel')
@click.option('--submit', is_flag=True, help='Actually submit calculation')
def main(codelabel, submit):
def example_binary_misture(raspa_code, submit=True):
"""Prepare and submit RASPA calculation with components mixture."""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist".format(codelabel))
sys.exit(1)

# parameters
parameters = Dict(
Expand Down Expand Up @@ -63,7 +55,7 @@ def main(codelabel, submit):
})

# Contructing builder
builder = code.get_builder()
builder = raspa_code.get_builder()
builder.parameters = parameters
builder.metadata.options = {
"resources": {
Expand Down Expand Up @@ -93,7 +85,20 @@ def main(codelabel, submit):
print("-----")


@click.command('cli')
@click.argument('codelabel')
@click.option('--submit', is_flag=True, help='Actually submit calculation')
def cli(codelabel, submit):
"""Click interface"""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist".format(codelabel))
sys.exit(1)
example_binary_misture(code, submit)


if __name__ == '__main__':
main() # pylint: disable=no-value-for-parameter
cli() # pylint: disable=no-value-for-parameter

# EOF
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,8 @@
CifData = DataFactory('cif') # pylint: disable=invalid-name


@click.command('cli')
@click.argument('codelabel')
@click.option('--previous_calc', '-p', required=True, type=int, help='PK of test_raspa_base.py calculation')
@click.option('--submit', is_flag=True, help='Actually submit calculation')
def main(codelabel, previous_calc, submit):
def example_binary_restart(raspa_code, previous_calc, submit=True):
"""Prepare and submit restart from simple RASPA calculation."""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist".format(codelabel))
sys.exit(1)

# parameters
parameters = Dict(
Expand Down Expand Up @@ -61,13 +52,13 @@ def main(codelabel, previous_calc, submit):
})

# framework
framework = CifData(file=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'files', 'TCC1RS.cif'))
framework = CifData(file=os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'files', 'TCC1RS.cif'))

# restart file
parent_folder = load_node(previous_calc).outputs.remote_folder

# Contructing builder
builder = code.get_builder()
builder = raspa_code.get_builder()
builder.framework = {
"tcc1rs": framework,
}
Expand Down Expand Up @@ -100,7 +91,21 @@ def main(codelabel, previous_calc, submit):
print("-----")


@click.command('cli')
@click.argument('codelabel')
@click.option('--previous_calc', '-p', required=True, type=int, help='PK of example_raspa_base.py calculation')
@click.option('--submit', is_flag=True, help='Actually submit calculation')
def cli(codelabel, previous_calc, submit):
"""Click interface"""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist".format(codelabel))
sys.exit(1)
example_binary_restart(code, previous_calc, submit)


if __name__ == '__main__':
main() # pylint: disable=no-value-for-parameter
cli() # pylint: disable=no-value-for-parameter

# EOF
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,9 @@
CifData = DataFactory('cif') # pylint: disable=invalid-name


@click.command('cli')
@click.argument('codelabel')
@click.option('--submit', is_flag=True, help='Actually submit calculation')
def main(codelabel, submit):
def example_block_pockets(raspa_code, submit=True):
"""Prepare and submit RASPA calculation with blocked pockets."""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist".format(codelabel))
sys.exit(1)

# parameters
parameters = Dict(
dict={
Expand Down Expand Up @@ -88,15 +81,15 @@ def main(codelabel, submit):

# frameworks
pwd = os.path.dirname(os.path.realpath(__file__))
framework_1 = CifData(file=os.path.join(pwd, 'files', 'IRMOF-1.cif'))
framework_10 = CifData(file=os.path.join(pwd, 'files', 'IRMOF-10.cif'))
framework_1 = CifData(file=os.path.join(pwd, '..', 'files', 'IRMOF-1.cif'))
framework_10 = CifData(file=os.path.join(pwd, '..', 'files', 'IRMOF-10.cif'))

# block pocket
block_pocket_1 = SinglefileData(file=os.path.join(pwd, 'files', 'IRMOF-1_test.block')).store()
block_pocket_10 = SinglefileData(file=os.path.join(pwd, 'files', 'IRMOF-10_test.block')).store()
block_pocket_1 = SinglefileData(file=os.path.join(pwd, '..', 'files', 'IRMOF-1_test.block')).store()
block_pocket_10 = SinglefileData(file=os.path.join(pwd, '..', 'files', 'IRMOF-10_test.block')).store()

# Contructing builder
builder = code.get_builder()
builder = raspa_code.get_builder()
builder.framework = {
"irmof_1": framework_1,
"irmof_10": framework_10,
Expand Down Expand Up @@ -136,7 +129,20 @@ def main(codelabel, submit):
print("In order to actually submit, add '--submit'")


@click.command('cli')
@click.argument('codelabel')
@click.option('--submit', is_flag=True, help='Actually submit calculation')
def cli(codelabel, submit):
"""Click interface"""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist".format(codelabel))
sys.exit(1)
example_block_pockets(code, submit)


if __name__ == '__main__':
main() # pylint: disable=no-value-for-parameter
cli() # pylint: disable=no-value-for-parameter

# EOF
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,9 @@
CifData = DataFactory('cif') # pylint: disable=invalid-name


@click.command('cli')
@click.argument('codelabel')
@click.option('--submit', is_flag=True, help='Actually submit calculation')
def main(codelabel, submit):
def example_block_pockets(raspa_code, submit=True):
"""Prepare and submit RASPA calculation with blocked pockets."""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist".format(codelabel))
sys.exit(1)

# parameters
parameters = Dict(
dict={
Expand Down Expand Up @@ -60,13 +53,13 @@ def main(codelabel, submit):

# framework
pwd = os.path.dirname(os.path.realpath(__file__))
framework = CifData(file=os.path.join(pwd, 'files', 'TCC1RS.cif'))
framework = CifData(file=os.path.join(pwd, '..', 'files', 'TCC1RS.cif'))

# block pocket
block_pocket_node = SinglefileData(file=os.path.join(pwd, 'files', 'block_pocket.block')).store()
block_pocket_node = SinglefileData(file=os.path.join(pwd, '..', 'files', 'block_pocket.block')).store()

# Contructing builder
builder = code.get_builder()
builder = raspa_code.get_builder()
builder.framework = {
"tcc1rs": framework,
}
Expand Down Expand Up @@ -100,7 +93,20 @@ def main(codelabel, submit):
print("In order to actually submit, add '--submit'")


@click.command('cli')
@click.argument('codelabel')
@click.option('--submit', is_flag=True, help='Actually submit calculation')
def cli(codelabel, submit):
"""Click interface"""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist".format(codelabel))
sys.exit(1)
example_block_pockets(code, submit)


if __name__ == '__main__':
main() # pylint: disable=no-value-for-parameter
cli() # pylint: disable=no-value-for-parameter

# EOF
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,8 @@
from aiida.orm import Code, Dict, CifData, SinglefileData


@click.command('cli')
@click.argument('codelabel')
@click.option('--submit', is_flag=True, help='Actually submit calculation')
def main(codelabel, submit):
def example_ff_files(raspa_code, submit=True):
"""Prepare and submit RASPA calculation with components mixture."""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist".format(codelabel))
sys.exit(1)

# parameters
parameters = Dict(
Expand Down Expand Up @@ -69,17 +61,17 @@ def main(codelabel, submit):

# Contructing builder
pwd = os.path.dirname(os.path.realpath(__file__))
builder = code.get_builder()
builder = raspa_code.get_builder()
builder.framework = {
"irmof_1": CifData(file=os.path.join(pwd, 'files', 'IRMOF-1_eqeq.cif')),
"irmof_1": CifData(file=os.path.join(pwd, '..', 'files', 'IRMOF-1_eqeq.cif')),
}
# Note: Here the SinglefileData in the dict are stored otherwise the dry_run crashes.
# However, this is not needed for real calculations (e.g., using --submit), since the work chains stores them.
builder.file = {
"file_1": SinglefileData(file=os.path.join(pwd, 'files', 'force_field_mixing_rules.def')).store(),
"file_2": SinglefileData(file=os.path.join(pwd, 'files', 'pseudo_atoms.def')).store(),
"file_3": SinglefileData(file=os.path.join(pwd, 'files', 'CO2.def')).store(),
"file_4": SinglefileData(file=os.path.join(pwd, 'files', 'N2.def')).store(),
"file_1": SinglefileData(file=os.path.join(pwd, '..', 'files', 'force_field_mixing_rules.def')).store(),
"file_2": SinglefileData(file=os.path.join(pwd, '..', 'files', 'pseudo_atoms.def')).store(),
"file_3": SinglefileData(file=os.path.join(pwd, '..', 'files', 'CO2.def')).store(),
"file_4": SinglefileData(file=os.path.join(pwd, '..', 'files', 'N2.def')).store(),
}
builder.parameters = parameters
builder.metadata.options = {
Expand Down Expand Up @@ -113,7 +105,20 @@ def main(codelabel, submit):
print("-----")


@click.command('cli')
@click.argument('codelabel')
@click.option('--submit', is_flag=True, help='Actually submit calculation')
def cli(codelabel, submit):
"""Click interface"""
try:
code = Code.get_from_string(codelabel)
except NotExistent:
print("The code '{}' does not exist".format(codelabel))
sys.exit(1)
example_ff_files(code, submit)


if __name__ == '__main__':
main() # pylint: disable=no-value-for-parameter
cli() # pylint: disable=no-value-for-parameter

# EOF
Loading

0 comments on commit b9ea033

Please sign in to comment.