Skip to content

Commit

Permalink
Update blop and prepare agent
Browse files Browse the repository at this point in the history
  • Loading branch information
XPD_Operator committed May 10, 2024
2 parents 087852c + ae28eda commit 08146b4
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 29 deletions.
3 changes: 3 additions & 0 deletions scripts/_data_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ def read_qepro_by_stream(uid, stream_name='primary', data_agent='tiled', beamlin



## TODO: add reading scattering data
# def read_scatter_by_stream(uid, stream_name='scattering', data_agent='tiled', beamline_acronym='xpd-ldrd20-31'):
# return scatter_dic, metadata_dic

## Get uids from data folders through daily experiments for export database for ML
## Read uid from **fluorescence** folder
Expand Down
141 changes: 141 additions & 0 deletions scripts/_pdf_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import pymatgen as pm
from diffpy.pdffit2 import PdfFit
from diffpy.Structure import loadStructure
from pymatgen.io.cif import CifWriter
from pymatgen.io.cif import CifParser
import os



def _no_oxidation_cif(cif_file):
parser = CifParser(cif_file)
structure = parser.get_structures()[0]
structure.remove_oxidation_states()
print(structure, '\n\n')
cif_pym = os.path.dirname(cif_file) + '/' + os.path.basename(cif_file)[:-4] + '_pym.cif'
w = CifWriter(structure,symprec=0.1)
w.write_file(cif_pym)

return cif_pym



def _pdffit2_CsPbX3(gr_data, cif_list, qmax=18, qdamp=0.031, qbroad=0.032, fix_APD=True):

# Initialize the CifParser with the path to your .cif file
# Parse the .cif file
pym_cif = []
for cif in cif_list:
cif_new = _no_oxidation_cif(cif)
pym_cif.append(cif_new)

# Create new PDF calculator object.
pf = PdfFit()

# Load experimental x-ray PDF data
# qmax = 20.0 # Q-cutoff used in PDF calculation in 1/A
# qdamp = 0.03 # instrument Q-resolution factor, responsible for PDF decay
pf.read_data(gr_data, 'X', qmax, qdamp)

# Load and add structure ------------------------------------------------------------------
for pym in pym_cif:
stru = loadStructure(pym)
stru.Uisoequiv = 0.04
stru.title = os.path.basename(pym)[:-4]
#Add loaded .cif
pf.add_structure(stru)

# set contrains for lattice parameter, ADP
_set_CsPbBr3_constrain(pf, phase_idx=1, fix_APD=fix_APD)

# set constrain for data scale
pf.constrain(pf.dscale, '@902')
pf.setpar(902, 0.65)

# Set value for Qdamp, Qbraod
pf.setvar(pf.qdamp, qdamp)
pf.setvar(pf.qbroad, qbroad)

# Refine
pf.pdfrange(1, 2.5, 60)
pf.refine()


phase_fraction = pf.phase_fractions()['mass']

particel_size = []
for i in range(pf.num_phases()):
pf.setphase(i+1)
particel_size.append(pf.getvar(pf.spdiameter))

return phase_fraction, particel_size



'''
lat_dic = {'a':11, 'b':12, 'c':13}
'''
def _set_CsPbBr3_constrain(PDF_calculator_object, phase_idx=1, fix_APD=True):
pf = PDF_calculator_object
pf.setphase(phase_idx)

# Refine lattice parameters a, b, c.
pf.constrain(pf.lat(1), "@11")
pf.constrain(pf.lat(2), "@12")
pf.constrain(pf.lat(3), "@13")
# set initial value of parameter @1, @2, @3
pf.setpar(11, pf.lat(1))
pf.setpar(12, pf.lat(2))
pf.setpar(13, pf.lat(3))

# Refine phase scale factor. Right side can have formulas.
pf.constrain('pscale', '@111')
pf.setpar(111, 0.5)
# pf.setpar(20, pf.getvar(pf.pscale) / 2.0)

# Refine sharpening factor for correlated motion of close atoms.
pf.constrain(pf.delta2, '@122')
pf.setpar(122, 6.87)

# Refine diameter for the spherical particle
pf.constrain(pf.spdiameter, '@133')
pf.setpar(133, 46)

# Set temperature factors isotropic to each atom
# idx starts from 1 not 0
# 1-4: Cs
for idx in range(1, 5):
pf.constrain(pf.u11(idx), '@101')
pf.constrain(pf.u22(idx), '@101')
pf.constrain(pf.u33(idx), '@101')
pf.setpar(101, 0.029385)

# 5-8: Pb
for idx in range(5, 9):
pf.constrain(pf.u11(idx), '@102')
pf.constrain(pf.u22(idx), '@102')
pf.constrain(pf.u33(idx), '@102')
pf.setpar(102, 0.027296)

# 9-16: Br
for idx in range(9, 17):
pf.constrain(pf.u11(idx), '@103')
pf.constrain(pf.u22(idx), '@103')
pf.constrain(pf.u33(idx), '@103')
pf.setpar(103, 0.041577)

# 16-20: Br
for idx in range(17, 21):
pf.constrain(pf.u11(idx), '@104')
pf.constrain(pf.u22(idx), '@104')
pf.constrain(pf.u33(idx), '@104')
pf.setpar(104, 0.028164)


if fix_APD:
for par in [101, 102, 103, 104]:
pf.fixpar(par)




58 changes: 56 additions & 2 deletions scripts/_synthesis_queue_RM.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def synthesis_queue(
set_target_list = set_target_list.tolist()


# 0. stop infuese for all pumps
flowplan = BPlan('stop_group', pump_list + [wash_tube[1]])
RM.item_add(flowplan, pos=pos)


for i in range(len(rate_list)):
# for i in range(2):
## 1. Set i infuese rates
Expand All @@ -76,7 +81,12 @@ def synthesis_queue(


## 2. Start infuese
flowplan = BPlan('start_group_infuse', pump_list, rate_list[i])
if precursor_list[-1] == 'Toluene':
flowplan = BPlan('start_group_infuse', pump_list[:-1], rate_list[i][:-1])

else:
flowplan = BPlan('start_group_infuse', pump_list, rate_list[i])

RM.item_add(flowplan, pos=pos)


Expand Down Expand Up @@ -110,6 +120,14 @@ def synthesis_queue(
restplan = BPlan('wait_equilibrium2', mixer_pump_list, ratio=rest_time)
RM.item_add(restplan, pos=pos)


## 3.1 Wait for 30 secpnds for post dilute
if precursor_list[-1] == 'Toluene':
flowplan = BPlan('start_group_infuse', [pump_list[-1]], [rate_list[i][-1]])
RM.item_add(flowplan, pos=pos)

restplan = BPlan('sleep_sec_q', 60)
RM.item_add(restplan, pos=pos)


## 4-1. Take a fluorescence peak to check reaction
Expand Down Expand Up @@ -155,7 +173,7 @@ def synthesis_queue(
###### Kafka analyze data here. #######

## 7. Wash the loop and mixer
wash_tube_queue(pump_list, wash_tube, rate_unit,
wash_tube_queue2(pump_list, wash_tube, rate_unit,
pos=[pos,pos,pos,pos,pos],
zmq_control_addr=zmq_control_addr,
zmq_info_addr=zmq_info_addr)
Expand Down Expand Up @@ -209,6 +227,42 @@ def wash_tube_queue(pump_list, wash_tube, rate_unit,



def wash_tube_queue2(pump_list, wash_tube, rate_unit,
pos=[0,1,2,3,4],
zmq_control_addr='tcp://localhost:60615',
zmq_info_addr='tcp://localhost:60625'):

RM = REManagerAPI(zmq_control_addr=zmq_control_addr, zmq_info_addr=zmq_info_addr)

### Stop all infusing pumps
flowplan = BPlan('stop_group', pump_list)
RM.item_add(flowplan, pos=pos[0])


### Set up washing tube/loop
flowplan = BPlan('set_group_infuse2', [wash_tube[0], wash_tube[3]], [wash_tube[1], wash_tube[4]],
rate_list=[wash_tube[2], wash_tube[5]],
target_vol_list=['30 ml', '15 ml'],
set_target_list=[False, False],
rate_unit=rate_unit)
RM.item_add(flowplan, pos=pos[1])


### Start washing tube/loop
flowplan = BPlan('start_group_infuse', [wash_tube[1], wash_tube[4]], [wash_tube[2], wash_tube[5]])
RM.item_add(flowplan, pos=pos[2])


### Wash loop/tube for xxx seconds
restplan = BPlan('sleep_sec_q', wash_tube[6])
RM.item_add(restplan, pos=pos[3])



### Stop washing
flowplan = BPlan('stop_group', [wash_tube[1], wash_tube[4]])
RM.item_add(flowplan, pos=pos[4])




Expand Down
Loading

0 comments on commit 08146b4

Please sign in to comment.