Skip to content

Commit

Permalink
update pressure input method
Browse files Browse the repository at this point in the history
  • Loading branch information
srmnitc committed Apr 4, 2022
1 parent 37546b2 commit 2bd7a2f
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 153 deletions.
88 changes: 78 additions & 10 deletions calphy/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import yaml
import itertools
import shutil
import numpy as np

class InputTemplate:
def __init__(self):
Expand Down Expand Up @@ -173,27 +174,94 @@ def pressure(self):

@pressure.setter
def pressure(self, val):
"""
Pressure input can be of many diff types:
Input iso fix_lattice Mode add. constraints
1. None True True any No
2. scalar True False any No
3. list of scalar len 1 True False any No
4. list of scalar len 2 True False ps No
5. list of scalar len 3 False False any All terms equal
6. list of list len 1x3 False False any Each inner term equal
7. list of list len 2x3 False False ps Each inner term equal
"""
def _check_equal(val):
if not (val[0]==val[1]==val[2]):
return False
return True

self._pressure_input = val

error_message = "Available pressure types are of shape: None, 1, 3, (1x1), (2x1), (3x1), (2x3)"
# Case: 1
if val is None:
self._iso = True
self._fix_lattice = True
self._pressure = None
self._pressure_stop = None

# Cases: 3,4,5,6,7
elif isinstance(val, list):
if len(val) == 1:
self._pressure = val[0]
self._iso = True
self._fix_lattice = False
elif len(val) == 3:
if (val[0]==val[1]==val[2]):
shape = np.shape(val)
indx = shape[0]
indy = shape[1] if len(shape)==2 else None

if indx == 1:
if indy is None:
# Case: 3
self._iso = True
self._fix_lattice = False
self._pressure = val[0]
self._pressure_stop = val[0]
elif indy == 3:
# Case: 6
if _check_equal(val[0]):
self._iso = False
self._fix_lattice = False
self._pressure = val[0][0]
self._pressure_stop = val[0][0]
else:
raise NotImplementedError("Pressure should have px=py=pz")
else:
raise NotImplementedError(error_message)
elif indx == 2:
if indy is None:
# Case: 4
self._iso = True
self._fix_lattice = False
self._pressure = val[0]
self._pressure_stop = val[1]
elif indy == 3:
# Case: 7
self._iso = False
self._fix_lattice = False
if _check_equal(val[0]) and _check_equal(val[1]):
self._pressure = val[0][0]
self._pressure_stop = val[1][0]
else:
raise NotImplementedError("Pressure should have px=py=pz")
else:
raise NotImplementedError()
elif len(val) == 2:
self._pressure = val[0]
self._pressure_stop = val[1]
raise NotImplementedError(error_message)

elif indx == 3:
if indy is None:
# Case: 5
if _check_equal(val):
self._iso = False
self._fix_lattice = False
self._pressure = val[0]
self._pressure_stop = val[0]
else:
raise NotImplementedError("Pressure should have px=py=pz")
else:
raise NotImplementedError(error_message)
else:
raise NotImplementedError()

# Case: 2
else:
self._pressure = val
self._pressure_stop = val
self._iso = True
self._fix_lattice = False

Expand Down
161 changes: 18 additions & 143 deletions notebooks/running_from_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"import os\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import copy\n",
"import itertools"
"import copy"
]
},
{
Expand All @@ -24,133 +23,30 @@
"from calphy import Calculation, Solid, Liquid"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "814388d4-7e8e-47f3-8bcb-f56529e6b1ba",
"metadata": {},
"outputs": [],
"source": [
"from calphy.input import read_inputfile"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "0a76eb2f-0713-4693-8a59-9e0b09a0340a",
"metadata": {},
"outputs": [],
"source": [
"calcs = read_inputfile(\"input_new.yaml\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "46db247a-0148-4320-9b0a-f811a67c579f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[solid system with T=1200, P=0 in FCC lattice for mode ts,\n",
" liquid system with T=1200, P=0 in LQD lattice for mode ts]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(calcs)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "3628d7a3-f90f-4f4c-9511-feda2032f35b",
"metadata": {},
"outputs": [],
"source": [
"calcs = list(calcs)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "57b7fd2b-4e9f-4a62-9480-0922f5fab600",
"metadata": {},
"outputs": [],
"source": [
"x = itertools.product(calcs[0], calcs[1], [[1200, 1400]])"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "3992c262-65da-4426-9994-27042fb06422",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[({'lattice': 'FCC', 'lattice_constant': 0, 'reference_phase': 'solid'},\n",
" 0,\n",
" [1200, 1400]),\n",
" ({'lattice': 'LQD', 'lattice_constant': 0, 'reference_phase': 'liquid'},\n",
" 0,\n",
" [1200, 1400])]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(x)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "58f934e9-b2a2-4fda-8acc-361fcb94be52",
"id": "872e93c2-c3bf-4580-a1ef-77789019cf39",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"liquid system with T=1200, P=0 in LQD lattice for mode ts"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"2\n",
"True\n",
"False\n"
]
}
],
"source": [
"calcs[3]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "314f0ed3-e40c-4b2d-a142-e70758d9a790",
"metadata": {},
"outputs": [],
"source": [
"csol = Calculation()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "379918d5-0f64-4779-aa75-6df2d29a7556",
"metadata": {},
"outputs": [],
"source": [
"csol."
"csol = Calculation()\n",
"csol.pressure = [[1,1,]]\n",
"print(csol._pressure)\n",
"print(csol._pressure_stop)\n",
"print(csol._iso)\n",
"print(csol._fix_lattice)"
]
},
{
Expand Down Expand Up @@ -297,7 +193,7 @@
"metadata": {},
"outputs": [],
"source": [
"clqd.lattice = \"LQD\"\n",
"clqd.lattice = \"FCC\"\n",
"clqd.repeat = [5,5,5]\n",
"clqd.reference_phase = \"liquid\""
]
Expand All @@ -312,27 +208,6 @@
"simfolder = clqd.create_folders()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "9fb4a632-35da-42bd-b09d-2ef5267328f5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'/home/users/menonsqr/Repos/calphy/notebooks/ts-LQD-1200-0'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"simfolder"
]
},
{
"cell_type": "code",
"execution_count": 8,
Expand Down Expand Up @@ -431,7 +306,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.1"
"version": "3.10.4"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 2bd7a2f

Please sign in to comment.