Best Python code snippet using avocado_python
creator.py
Source:creator.py
...25 POTCAR_maker.writer(path_to_calc, elem_list)26def undeformed_lattice(a, b, c, alpha, beta, gamma):27 """Creates all necessary files to run a VASP job for initial undeformed structure"""28 calculation_type = "undeformed"29 new_lattice = Lattice.from_parameters(a, b, c, alpha, beta, gamma)30 single_run(calculation_type, new_lattice)31def applied_field(a, b, c, alpha, beta, gamma):32 """Creates all necessary files to run a VASP job for structure33 under applied field (value of the field is set in INCAR_maker)"""34 calculation_type = "Applied_Field"35 new_lattice = Lattice.from_parameters(a, b, c, alpha, beta, gamma)36 single_run(calculation_type, new_lattice)37def volumetric_deformation(n, a, b, c, alpha, beta, gamma):38 """Takes lattice parameters and scales all of them by deformation factor39 Prepares both compressed and expanded structures"""40 V_inc = 'V_' + str(1+n)41 V_dec = 'V_' + str(1-n)42 deformation_types = [V_dec, V_inc]43 for deformation_type in deformation_types:44 if deformation_type == V_dec:45 new_lattice = Lattice.from_parameters(a, b, c, alpha, beta, gamma)46 volume_before = new_lattice.volume47 new_lattice = new_lattice.scale((1 - n) * volume_before)48 single_run(deformation_type, new_lattice)49 if deformation_type == V_inc:50 new_lattice = Lattice.from_parameters(a, b, c, alpha, beta, gamma)51 volume_before = new_lattice.volume52 new_lattice = new_lattice.scale((1 + n) * volume_before)53 single_run(deformation_type, new_lattice)54def uniaxial_defromations(lattice_type, n, a, b, c, alpha, beta, gamma):55 """Takes lattice type as argument and depending on symmetry creates all necessary files to run VASP jobs for all56 possible independent deformations.57 Depending on symmetry create a 3x3 deformation matrix which determines weather a, b, c are deformed. This matrix is58 later passed to POSCAR_maker where it is used for adjusting the lattice matrix.59 Deformations are done both for increase and decrease of each lattice parameter.60 """61 # deformation factor 0.05 == 5%, deformation is done both for expansion and contraction.62 # creating names for deformations:63 a_inc = 'a_' + str(1+n)64 a_dec = 'a_' + str(1-n)65 b_inc = 'b_' + str(1+n)66 b_dec = 'b_' + str(1-n)67 c_inc = 'c_' + str(1+n)68 c_dec = 'c_' + str(1-n)69 if lattice_type == "cubic":70 deformation_types = [a_dec, a_inc]71 for deformation_type in deformation_types:72 if deformation_type == a_dec:73 a_d = a * pow((1 - n), (1/3))74 b_d = b * pow((1 - n), (1/3))75 c_d = c * pow((1 - n), (1/3))76 new_lattice = Lattice.from_parameters(a_d, b_d, c_d, alpha, beta, gamma)77 single_run(deformation_type, new_lattice)78 if deformation_type == a_inc:79 a_i = a * pow((1 + n), (1/3))80 b_i = b * pow((1 + n), (1/3))81 c_i = c * pow((1 + n), (1/3))82 new_lattice = Lattice.from_parameters(a_i, b_i, c_i, alpha, beta, gamma)83 single_run(deformation_type, new_lattice)84 elif lattice_type == "hexagonal":85 deformation_types = [a_dec, a_inc, c_inc, c_dec]86 for deformation_type in deformation_types:87 if deformation_type == a_dec:88 a_d = a * pow((1 - n), (1/2))89 b_d = b * pow((1 - n), (1/2))90 new_lattice = Lattice.from_parameters(a_d, b_d, c, alpha, beta, gamma)91 single_run(deformation_type, new_lattice)92 if deformation_type == c_dec:93 c_d = c * (1 - n)94 new_lattice = Lattice.from_parameters(a, b, c_d, alpha, beta, gamma)95 single_run(deformation_type, new_lattice)96 if deformation_type == a_inc:97 a_i = a * pow((1 + n), (1/2))98 b_i = b * pow((1 + n), (1/2))99 new_lattice = Lattice.from_parameters(a_i, b_i, c, alpha, beta, gamma)100 single_run(deformation_type, new_lattice)101 if deformation_type == c_inc:102 c_i = c * (1 + n)103 new_lattice = Lattice.from_parameters(a, b, c_i, alpha, beta, gamma)104 single_run(deformation_type, new_lattice)105 elif lattice_type == "rhombohedral":106 deformation_types = [a_dec, a_inc]107 for deformation_type in deformation_types:108 if deformation_type == a_dec:109 a_d = a * pow((1 - n), (1/3))110 b_d = b * pow((1 - n), (1/3))111 c_d = c * pow((1 - n), (1/3))112 new_lattice = Lattice.from_parameters(a_d, b_d, c_d, alpha, beta, gamma)113 single_run(deformation_type, new_lattice)114 if deformation_type == a_inc:115 a_i = a * pow((1 + n), (1/3))116 b_i = b * pow((1 + n), (1/3))117 c_i = c * pow((1 + n), (1/3))118 new_lattice = Lattice.from_parameters(a_i, b_i, c_i, alpha, beta, gamma)119 single_run(deformation_type, new_lattice)120 elif lattice_type == "tetragonal":121 deformation_types = [a_dec, a_inc, c_inc, c_dec]122 for deformation_type in deformation_types:123 if deformation_type == a_dec:124 a_d = a * pow((1 - n), (1/2))125 b_d = b * pow((1 - n), (1/2))126 new_lattice = Lattice.from_parameters(a_d, b_d, c, alpha, beta, gamma)127 single_run(deformation_type, new_lattice)128 if deformation_type == c_dec:129 c_d = c * (1 - n)130 new_lattice = Lattice.from_parameters(a, b, c_d, alpha, beta, gamma)131 single_run(deformation_type, new_lattice)132 if deformation_type == a_inc:133 a_i = a * pow((1 + n), (1/2))134 b_i = b * pow((1 + n), (1/2))135 new_lattice = Lattice.from_parameters(a_i, b_i, c, alpha, beta, gamma)136 single_run(deformation_type, new_lattice)137 if deformation_type == c_inc:138 c_i = c * (1 + n)139 new_lattice = Lattice.from_parameters(a, b, c_i, alpha, beta, gamma)140 single_run(deformation_type, new_lattice)141 elif lattice_type == "orthorhombic":142 deformation_types = [a_dec, b_dec, c_dec, a_inc, b_inc, c_inc]143 for deformation_type in deformation_types:144 if deformation_type == a_dec:145 a_d = a * (1 - n)146 new_lattice = Lattice.from_parameters(a_d, b, c, alpha, beta, gamma)147 single_run(deformation_type, new_lattice)148 if deformation_type == b_dec:149 b_d = b * (1 - n)150 new_lattice = Lattice.from_parameters(a, b_d, c, alpha, beta, gamma)151 single_run(deformation_type, new_lattice)152 if deformation_type == c_dec:153 c_d = c * (1 - n)154 new_lattice = Lattice.from_parameters(a, b, c_d, alpha, beta, gamma)155 single_run(deformation_type, new_lattice)156 if deformation_type == a_inc:157 a_i = a * (1 + n)158 new_lattice = Lattice.from_parameters(a_i, b, c, alpha, beta, gamma)159 single_run(deformation_type, new_lattice)160 if deformation_type == b_inc:161 b_i = b * (1 + n)162 new_lattice = Lattice.from_parameters(a, b_i, c, alpha, beta, gamma)163 single_run(deformation_type, new_lattice)164 if deformation_type == c_inc:165 c_i = c * (1 + n)166 new_lattice = Lattice.from_parameters(a, b, c_i, alpha, beta, gamma)167 single_run(deformation_type, new_lattice)168 elif lattice_type == "monoclinic":169 deformation_types = [a_dec, b_dec, c_dec, a_inc, b_inc, c_inc]170 for deformation_type in deformation_types:171 if deformation_type == a_dec:172 a_d = a * (1 - n)173 new_lattice = Lattice.from_parameters(a_d, b, c, alpha, beta, gamma)174 single_run(deformation_type, new_lattice)175 if deformation_type == b_dec:176 b_d = b * (1 - n)177 new_lattice = Lattice.from_parameters(a, b_d, c, alpha, beta, gamma)178 single_run(deformation_type, new_lattice)179 if deformation_type == c_dec:180 c_d = c * (1 - n)181 new_lattice = Lattice.from_parameters(a, b, c_d, alpha, beta, gamma)182 single_run(deformation_type, new_lattice)183 if deformation_type == a_inc:184 a_i = a * (1 + n)185 new_lattice = Lattice.from_parameters(a_i, b, c, alpha, beta, gamma)186 single_run(deformation_type, new_lattice)187 if deformation_type == b_inc:188 b_i = b * (1 + n)189 new_lattice = Lattice.from_parameters(a, b_i, c, alpha, beta, gamma)190 single_run(deformation_type, new_lattice)191 if deformation_type == c_inc:192 c_i = c * (1 + n)193 new_lattice = Lattice.from_parameters(a, b, c_i, alpha, beta, gamma)194 single_run(deformation_type, new_lattice)195 elif lattice_type == "triclinic":196 deformation_types = [a_dec, b_dec, c_dec, a_inc, b_inc, c_inc]197 for deformation_type in deformation_types:198 if deformation_type == a_dec:199 a_d = a * (1 - n)200 new_lattice = Lattice.from_parameters(a_d, b, c, alpha, beta, gamma)201 single_run(deformation_type, new_lattice)202 if deformation_type == b_dec:203 b_d = b * (1 - n)204 new_lattice = Lattice.from_parameters(a, b_d, c, alpha, beta, gamma)205 single_run(deformation_type, new_lattice)206 if deformation_type == c_dec:207 c_d = c * (1 - n)208 new_lattice = Lattice.from_parameters(a, b, c_d, alpha, beta, gamma)209 single_run(deformation_type, new_lattice)210 if deformation_type == a_inc:211 a_i = a * (1 + n)212 new_lattice = Lattice.from_parameters(a_i, b, c, alpha, beta, gamma)213 single_run(deformation_type, new_lattice)214 if deformation_type == b_inc:215 b_i = b * (1 + n)216 new_lattice = Lattice.from_parameters(a, b_i, c, alpha, beta, gamma)217 single_run(deformation_type, new_lattice)218 if deformation_type == c_inc:219 c_i = c * (1 + n)220 new_lattice = Lattice.from_parameters(a, b, c_i, alpha, beta, gamma)221 single_run(deformation_type, new_lattice)222def creator(datalist, datadir, def_factor=0.05, undeformed=True, hydrostatic=False, uniaxial=False, field=False):223 df = pd.read_csv(datalist, index_col=0, sep=',')224 with tqdm.tqdm(total=len(df.index)) as pbar: # A wrapper that creates nice progress bar225 pbar.set_description("Processing datalist")226 for item in df.index.tolist():227 pbar.update(1)228 ID = str(item)229 global path230 path = output_path + '/' + str(ID) + '/' # Prepare folder single ID (all subfolders will go there)231 if os.path.exists(path): # !WARNING! Overwrites existing path!232 shutil.rmtree(path) #233 os.makedirs(path) #234 # Take all information from poscar as list of strings:...
latt.py
Source:latt.py
...49 def vc(self):50 return self._c5152 @classmethod53 def from_parameters(cls, a, b, c, alpha, beta, gamma):54 """55 Construct a new Lattice object from parameters.56 Args:57 a:58 b:59 c:60 alpha:61 beta:62 gamma:6364 Returns:6566 """67 angles_r = np.radians([alpha, beta, gamma])68 cos_alpha, cos_beta, cos_gamma = np.cos(angles_r)69 sin_alpha, sin_beta, sin_gamma = np.sin(angles_r)70 val = cls._abs_cap((cos_alpha * cos_beta - cos_gamma) / (sin_alpha * sin_beta))71 va = [a * sin_beta, 0.0, a * cos_beta]72 vb = [-b * sin_alpha * np.cos(np.arccos(val)),73 b * sin_alpha * np.sin(np.arccos(val)), b * cos_alpha]74 vc = [0.0, 0.0, float(c)]75 return cls(np.asarray([va, vb, vc]))7677 @staticmethod78 def _abs_cap(val, max_abs_val=1):79 """80 Return the value with its absolute value capped at max_abs_val.8182 Particularly useful in passing values to trignometric functions where83 numerical errors may result in an argument > 1 being passed in.8485 Args:8687 val (float): Input value.8889 max_abs_val (float): The maximum absolute value for val. Defaults to 1.9091 Returns:92 val if abs(val) < 1 else sign of val * max_abs_val.93 """94 return max(min(val, max_abs_val), -max_abs_val)9596 @classmethod97 def cubic(cls, a):98 """Construct cubic Lattice from lattice parameter information."""99 return cls.from_parameters(a, a, a, 90, 90, 90)100101 @classmethod102 def tetragonal(cls, a, c):103 """Construct tetragonal Lattice from lattice parameter information."""104 return cls.from_parameters(a, a, c, 90, 90, 90)105106 @classmethod107 def orthorhombic(cls, a, b, c):108 """Construct orthorhombic Lattice."""109 return cls.from_parameters(a, b, c, 90, 90, 90)110111 @classmethod112 def monoclinic(cls, a, b, c, beta):113 """Construct monoclinic Lattice from lattice parameter information."""114 return cls.from_parameters(a, b, c, 90, beta, 90)115116 @classmethod117 def hexagonal(cls, a, c):118 """Construct hexagonal Lattice from lattice parameter information."""119 return cls.from_parameters(a, a, c, 90, 90, 120)120121 @classmethod122 def rhombohedral(cls, a, alpha):123 """Construct rhombohedral Lattice."""124 return cls.from_parameters(a, a, a, alpha, alpha, alpha)125126 @property127 def lattice(self):128 """129130 Returns: lattice matrix.131132 """133 return self._lat134135 def inv_lattice(self):136 """137138 Returns: inverse lattice matrix.
...
message_back.py
Source:message_back.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3import os4from flask import Flask, Response, request5import simplejson as json6import plivoxml7import plivo8PLIVO_AUTH_ID = "MANTLJODIXMTJKNJDMYJ"9PLIVO_AUTH_TOKEN = "MWY5MzIxNjAyYWUzOTc1MjZjMDViNDYxNTAwYTFh"10plivo_number = "14154290712"11data = []12app = Flask(__name__)13@app.route('/response/message_back/', methods=['GET', 'POST'])14def message_back():15 if request.method == 'POST':16 print request.form17 from_num = request.form.get('From')18 from_parameters = request.form.get('Text')19 from_parameters = from_parameters.strip().split()20 print from_parameters21 person = {}22 person['phone_num'] = long(from_num)23 person['country_code'] = from_parameters[0]24 person['pregancy_stage'] = int(from_parameters[1])25 person['has_smartphone'] = False 26 person['language'] = 'english'27 person['responsiveness'] = 528 29 add_person(person)30 31 subscriber_msg = "You are now subscribed to the feed"32 message_params = {33 'src':plivo_number,34 'dst':from_num,35 'text':subscriber_msg,36 }37 p = plivo.RestAPI(PLIVO_AUTH_ID, PLIVO_AUTH_TOKEN)38 res = p.send_message(message_params)39 return str(res)40 41 42@app.route('/subscribers/', methods=['GET'])43def get_subscriber():44 global data45 read_data()46 country_code = request.args.get('country_code')47 if country_code == None:48 return Response( json.dumps(data), mimetype="application/json") 49 else:50 return_data = filter(lambda x: x['country_code'] == country_code, data)51 return Response( json.dumps(return_data), mimetype="application/json") 52 53def save_data():54 global data55 with open('subscribers.txt', 'w') as fp:56 json.dump(data, fp)57 58def read_data():59 global data60 with open("subscribers.txt", 'r') as fp:61 data = json.load(fp) 62def add_person(person_dict):63 print person_dict64 global data65 read_data()66 data.append(person_dict)67 save_data()68if __name__ == '__main__':...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!