Best Python code snippet using tox_python
reader_ (stephen-desktop-linux's conflicted copy 2019-08-24).py
Source:reader_ (stephen-desktop-linux's conflicted copy 2019-08-24).py
...10 self.atomlistName = atomlistName11 self.trajDir = trajDir12 self.trajExt = trajExt13 self.File_TOP = File_TOP14 self.homedir = self.get_homedir()15 self.trajlist_list = self.get_trajlist(trajlistName, self.homedir)16 self.atom_indices = self.get_atom_indices( atomlistName, self.homedir)17 #self.framelist = self.get_framelist()18 '''19 def walk_dir(self,input_traj_dir, input_traj_ext,topdown=True):20 frame_list = []21 for root, dirs, files in os.walk(input_traj_dir, topdown):22 for name in files:23 if os.path.splitext(name)[1] == input_traj_ext:24 frame_list.append( os.path.join( root, name ))25 return frame_list26 def get_trajlist(self,trajlist_filename, trajlist_dir):27 trajlist_file = open( trajlist_filename )28 #trajlist_dir = self.get_homedir()29 trajlist_list = []30 for line in trajlist_file:31 list = trajlist_dir + '/' + line.rstrip("\n")32 list = list.strip() # remove the spaces in the end line, thanks to Yang Xi for reporting this bug, Stephen 2014120833 trajlist_list.append( list )34 trajlist_file.close()35 return trajlist_list36 def get_homedir(self):37 return os.getcwd()38 def get_atom_indices(self, indices_filename, indices_dir):39 if indices_filename != None:40 atom_indices = np.loadtxt(indices_filename, dtype=np.int32).tolist()41 return atom_indices42 else:43 return None44 def get_framefile_list(self, trajlist_list):45 framefile_list = []46 #trajlist_list = self.trajlist_list47 Ext = '.' + self.trajExt48 for trajlist in trajlist_list:49 framefile_list.extend( self.walk_dir(trajlist, Ext))50 return framefile_list51class XTCReader(TrajReader):52 def __init__(self, trajlistName, atomlistName, homedir, trajExt, File_TOP, nSubSample=None):53 self.trajlistName = trajlistName54 self.atomlistName = atomlistName55 self.trajDir = homedir56 self.trajExt = trajExt57 self.File_TOP = File_TOP58 self.homedir = homedir59 self.nSubSample = nSubSample60 #self.homedir = self.get_homedir()61 self.trajlist_list = self.get_trajlist(trajlistName, self.homedir)62 self.atom_indices = self.get_atom_indices( atomlistName, self.homedir)63 self.framefile_list = self.get_framefile_list(self.trajlist_list)64 self.trajs, self.traj_len = self.read_trajs(self.framefile_list)65 def read_trajs(self, framelist):66 trajs = []67 traj_len = []68 print("Reading trajs...")69 for frame in framelist:70 print('Reading: ', frame)71 #traj = md.load(frame, top=self.File_TOP, atom_indices=self.atom_indices)72 traj = md.load(frame, discard_overlapping_frames=True, top=self.File_TOP, #atom_indices=self.atom_indices,73 stride=self.nSubSample)74 #traj = traj[:-1] #remove last one75 trajs.append(traj)76 traj_len.append(len(traj))77 len_trajs = len(trajs)78 whole_trajs= reduce(operator.add, (trajs[i] for i in range(len_trajs)))79 print("Done.")80 print(len_trajs, "trajs,", len(whole_trajs), "frames.")81 #print "debug output: len_trajs", len_trajs, "len_whole_trajs", len(whole_trajs)82 return whole_trajs, traj_len83 def get_phipsi(self, trajs, phi, psi):84 #phi = [6, 8, 14, 16]85 #psi = [4, 6, 8, 14]86 PHI_INDICES = []87 PSI_INDICES = []88 for i in range(len(phi)):89 PHI_INDICES.append(self.atom_indices.index(phi[i]))90 PSI_INDICES.append(self.atom_indices.index(psi[i]))91 #len_trajs = len(trajs)92 print("PSI:", PSI_INDICES)93 print("PHI:", PHI_INDICES)94 phi_angles = md.compute_dihedrals(trajs, [PHI_INDICES]) * 180.0 / np.pi95 psi_angles = md.compute_dihedrals(trajs, [PSI_INDICES]) * 180.0 / np.pi96 #phi_psi=np.column_stack((phi_angles, psi_angles))97 #return phi_psi98 return phi_angles, psi_angles99class DCDReader(TrajReader):100 def __init__(self, trajlistName, atomlistName, homedir, trajExt, File_TOP, nSubSample):101 self.trajlistName = trajlistName102 self.atomlistName = atomlistName103 self.trajDir = homedir104 self.trajExt = trajExt105 self.File_TOP = File_TOP106 self.homedir = homedir107 self.nSubSample = nSubSample108 #self.homedir = self.get_homedir()109 self.trajlist_list = self.get_trajlist(trajlistName, self.homedir)110 self.atom_indices = self.get_atom_indices( atomlistName, self.homedir)111 def read_trajs(self, framelist):112 #data = []113 trajs = []114 for frame in framelist:115 #framedata = []116 #print 'Reading: ', frame117 traj = md.load_dcd(frame, self.File_TOP, stride=self.nSubSample)118 trajs.append(traj)119 return trajs120class AmberReader(TrajReader):121 def __init__(self, trajlistName, atomlistName, homedir, trajExt, File_TOP, nSubSample):122 self.trajlistName = trajlistName123 self.atomlistName = atomlistName124 self.trajDir = homedir125 self.trajExt = trajExt126 self.File_TOP = File_TOP127 self.homedir = homedir128 self.nSubSample = nSubSample129 #self.homedir = self.get_homedir()130 self.trajlist_list = self.get_trajlist(trajlistName, self.homedir)131 self.atom_indices = self.get_atom_indices( atomlistName, self.homedir)132 def read_trajs(self, framelist):133 #data = []134 trajs = []135 for frame in framelist:136 #framedata = []137 print('Reading: ', frame)138 traj = md.load_netcdf(frame, self.File_TOP, stride=self.nSubSample)139 trajs.append(traj)140 return trajs141class VectorReader(TrajReader):142 def __init__(self, trajlistName, atomlistName=None, homedir='.', trajExt='txt', File_TOP=None, stride=None, framefile=None):143 self.trajlistName = trajlistName144 #self.atomlistName = atomlistName145 self.trajDir = homedir146 self.trajExt = trajExt147 #self.File_TOP = File_TOP148 self.homedir = homedir149 self.stride = stride150 #self.homedir = self.get_homedir()151 if framefile is not None:152 self.framefile_list = self.get_framefile(framefile)153 else:154 self.trajlist_list = self.get_trajlist(trajlistName, self.homedir)155 self.framefile_list = self.get_framefile_list(self.trajlist_list)156 #self.atom_indices = self.get_atom_indices( atomlistName, self.homedir)157 self.trajs, self.traj_len = self.read_trajs(self.framefile_list)158 def read_trajs(self, framelist):159 #data = []160 trajs = []161 traj_len = []162 for frame in framelist:163 #framedata = []164 print('Reading: ', frame)...
reader_.py
Source:reader_.py
...10 self.atomlistName = atomlistName11 self.trajDir = trajDir12 self.trajExt = trajExt13 self.File_TOP = File_TOP14 self.homedir = self.get_homedir()15 self.trajlist_list = self.get_trajlist(trajlistName, self.homedir)16 self.atom_indices = self.get_atom_indices( atomlistName, self.homedir)17 #self.framelist = self.get_framelist()18 '''19 def walk_dir(self,input_traj_dir, input_traj_ext,topdown=True):20 frame_list = []21 for root, dirs, files in os.walk(input_traj_dir, topdown):22 for name in files:23 if os.path.splitext(name)[1] == input_traj_ext:24 frame_list.append( os.path.join( root, name ))25 return frame_list26 def get_trajlist(self,trajlist_filename, trajlist_dir):27 trajlist_file = open( trajlist_filename )28 #trajlist_dir = self.get_homedir()29 trajlist_list = []30 for line in trajlist_file:31 list = trajlist_dir + '/' + line.rstrip("\n")32 list = list.strip() # remove the spaces in the end line, thanks to Yang Xi for reporting this bug, Stephen 2014120833 trajlist_list.append( list )34 trajlist_file.close()35 return trajlist_list36 def get_homedir(self):37 return os.getcwd()38 def get_atom_indices(self, indices_filename, indices_dir):39 if indices_filename != None:40 atom_indices = np.loadtxt(indices_filename, dtype=np.int32).tolist()41 return atom_indices42 else:43 return None44 def get_framefile_list(self, trajlist_list):45 framefile_list = []46 #trajlist_list = self.trajlist_list47 Ext = '.' + self.trajExt48 for trajlist in trajlist_list:49 framefile_list.extend(self.walk_dir(trajlist, Ext))50 return framefile_list51class XTCReader(TrajReader):52 def __init__(self, trajlistName, atomlistName, homedir, trajExt, File_TOP, nSubSample=None):53 self.trajlistName = trajlistName54 self.atomlistName = atomlistName55 self.trajDir = homedir56 self.trajExt = trajExt57 self.File_TOP = File_TOP58 self.homedir = homedir59 self.nSubSample = nSubSample60 #self.homedir = self.get_homedir()61 self.trajlist_list = self.get_trajlist(trajlistName, self.homedir)62 self.atom_indices = self.get_atom_indices( atomlistName, self.homedir)63 self.framefile_list = self.get_framefile_list(self.trajlist_list)64 self.trajs, self.traj_len = self.read_trajs(self.framefile_list)65 def read_trajs(self, framelist):66 trajs = []67 traj_len = []68 print("Reading trajs...")69 for frame in framelist:70 print('Reading: ', frame)71 #traj = md.load(frame, top=self.File_TOP, atom_indices=self.atom_indices)72 traj = md.load(frame, discard_overlapping_frames=True, top=self.File_TOP, #atom_indices=self.atom_indices,73 stride=self.nSubSample)74 #traj = traj[:-1] #remove last one75 trajs.append(traj)76 traj_len.append(len(traj))77 len_trajs = len(trajs)78 whole_trajs= reduce(operator.add, (trajs[i] for i in range(len_trajs)))79 print("Done.")80 print(len_trajs, "trajs,", len(whole_trajs), "frames.")81 #print "debug output: len_trajs", len_trajs, "len_whole_trajs", len(whole_trajs)82 return whole_trajs, traj_len83 def get_phipsi(self, trajs, phi, psi):84 #phi = [6, 8, 14, 16]85 #psi = [4, 6, 8, 14]86 PHI_INDICES = []87 PSI_INDICES = []88 for i in range(len(phi)):89 PHI_INDICES.append(self.atom_indices.index(phi[i]))90 PSI_INDICES.append(self.atom_indices.index(psi[i]))91 #len_trajs = len(trajs)92 print("PSI:", PSI_INDICES)93 print("PHI:", PHI_INDICES)94 phi_angles = md.compute_dihedrals(trajs, [PHI_INDICES]) * 180.0 / np.pi95 psi_angles = md.compute_dihedrals(trajs, [PSI_INDICES]) * 180.0 / np.pi96 #phi_psi=np.column_stack((phi_angles, psi_angles))97 #return phi_psi98 return phi_angles, psi_angles99class DCDReader(TrajReader):100 def __init__(self, trajlistName, atomlistName, homedir, trajExt, File_TOP, nSubSample):101 self.trajlistName = trajlistName102 self.atomlistName = atomlistName103 self.trajDir = homedir104 self.trajExt = trajExt105 self.File_TOP = File_TOP106 self.homedir = homedir107 self.nSubSample = nSubSample108 #self.homedir = self.get_homedir()109 self.trajlist_list = self.get_trajlist(trajlistName, self.homedir)110 self.atom_indices = self.get_atom_indices( atomlistName, self.homedir)111 def read_trajs(self, framelist):112 #data = []113 trajs = []114 for frame in framelist:115 #framedata = []116 #print 'Reading: ', frame117 traj = md.load_dcd(frame, self.File_TOP, stride=self.nSubSample)118 trajs.append(traj)119 return trajs120class AmberReader(TrajReader):121 def __init__(self, trajlistName, atomlistName, homedir, trajExt, File_TOP, nSubSample):122 self.trajlistName = trajlistName123 self.atomlistName = atomlistName124 self.trajDir = homedir125 self.trajExt = trajExt126 self.File_TOP = File_TOP127 self.homedir = homedir128 self.nSubSample = nSubSample129 #self.homedir = self.get_homedir()130 self.trajlist_list = self.get_trajlist(trajlistName, self.homedir)131 self.atom_indices = self.get_atom_indices( atomlistName, self.homedir)132 def read_trajs(self, framelist):133 #data = []134 trajs = []135 for frame in framelist:136 #framedata = []137 print('Reading: ', frame)138 traj = md.load_netcdf(frame, self.File_TOP, stride=self.nSubSample)139 trajs.append(traj)140 return trajs141class VectorReader(TrajReader):142 def __init__(self, trajlistName, atomlistName=None, homedir='.', trajExt='txt', File_TOP=None, stride=None, framefile=None):143 self.trajlistName = trajlistName144 #self.atomlistName = atomlistName145 self.trajDir = homedir146 self.trajExt = trajExt147 #self.File_TOP = File_TOP148 self.homedir = homedir149 self.stride = stride150 #self.homedir = self.get_homedir()151 if framefile is not None:152 self.framefile_list = self.get_framefile(framefile)153 else:154 self.trajlist_list = self.get_trajlist(trajlistName, self.homedir)155 self.framefile_list = self.get_framefile_list(self.trajlist_list)156 #self.atom_indices = self.get_atom_indices( atomlistName, self.homedir)157 self.trajs, self.traj_len = self.read_trajs(self.framefile_list)158 def read_trajs(self, framelist):159 #data = []160 trajs = []161 traj_len = []162 for frame in framelist:163 #framedata = []164 print('Reading: ', frame)...
config.py
Source:config.py
...5from synapse_admin.utils import dirs6from synapse_admin.types.config import Config, LogedUser7def save(server_url, user_id, access_token):8 config = Config(server_url, LogedUser(user_id, access_token))9 with open(dirs.get_homedir()+"/.synapse-admin.config.json", "w") as conf_file:10 if dataclasses.is_dataclass(config):11 json.dump(dataclasses.asdict(config), conf_file)12def load():13 if not Path(dirs.get_homedir()+"/.synapse-admin.config.json").is_file():14 print("Config file not found. Please init synapse-admin by command: synapse-admin init")15 exit(1)16 17 with open(dirs.get_homedir()+"/.synapse-admin.config.json", "r") as conf_file:18 config_dict = json.load(conf_file)19 config = Config(server_url=config_dict.get("server_url"))20 if config_dict.get("loged_as"):21 config.loged_as = LogedUser(**config_dict["loged_as"])22 ...
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!!