def build_model(self): """ Generates and returns model content based on the values set to object. """ # Add Action's date and type model = DM() model['action'] = DM() model['action']['date'] = str(self.date) model['action']['type'] = self.type # Add any related potentials for potential in self.potentials: model['action'].append('potential', potential.build_model()['potential']) # Add comments if self.comment is not None: model['action']['comment'] = self.comment self._set_model(model) return model
def buildpaircoeff(self): """Builds the pair_coeff command lines""" if self.symbols is not None: symbols = self.symbols else: symbols = self.elements if len(symbols) != len(self.paramfiles): raise ValueError('a paramfile is needed for each symbol/element') paircoeffs = [] for symbol, paramfile in zip(symbols, self.paramfiles): paircoeff = DM() paircoeff['interaction'] = DM([('symbol', [symbol, symbol])]) paircoeff['term'] = DM([('file', paramfile)]) paircoeffs.append(paircoeff) if len(paircoeffs) == 0: paircoeffs = paircoeffs[0] return paircoeffs
def asmodel(self): """ Returns the object info as data model content Returns ---------- DataModelDict The data model content. """ model = DM() model['artifact'] = DM() model['artifact']['web-link'] = DM() if self.url is not None: model['artifact']['web-link']['URL'] = self.url if self.label is not None: model['artifact']['web-link']['label'] = self.label if self.filename is not None: model['artifact']['web-link']['link-text'] = self.filename return model
def unset_database(name=None): """ Deletes the settings for a pre-defined database from the settings file. Parameters ---------- name : str The name assigned to a pre-defined database. """ # Get information from settings file settings = load_settings() databases = settings['iprPy-defined-parameters'].aslist('database') # Ask for name if not given if name is None: if len(databases) > 0: print('Select a database:') for i, database in enumerate(databases): print(i + 1, database['name']) choice = screen_input(':') try: choice = int(choice) except: name = choice else: name = databases[choice - 1]['name'] else: print('No databases currently set') return None # Verify listed name exists else: try: settings.find('database', yes={'name': name}) except: raise ValueError(f'Database {name} not found') print(f'Database {name} found') test = screen_input('Delete settings? (must type yes):') if test == 'yes': if len(databases) == 1: del (settings['iprPy-defined-parameters']['database']) else: new = DM() for database in databases: if database['name'] != name: new.append('database', database) settings['iprPy-defined-parameters']['database'] = new['database'] save_settings(settings) print(f'Settings for database {name} successfully deleted')
def load_model(self, model): """ Loads record contents from a given model. Parameters ---------- model : str or DataModelDict The model contents of the record to load. """ model = DM(model).find('system') self.formula = model.get('chemical-formula', None) self.elements = model.get('element', None)
def __initial_setup(t, v): """ Pulls out the singular values in terms, t, and variables, v. Asserts that multi-valued variables are of appropriate lengths. """ v_dict = DM() #read in run and library directory information run_directory = atomman_input.get_value(v, 'run_directory') lib_directory = atomman_input.get_value(v, 'lib_directory') #read in the simulation-dependent singular valued variables v_dict['lammps_command'] = atomman_input.get_value(v, 'lammps_command') v_dict['mpi_command'] = atomman_input.get_value(v, 'mpi_command', '') v_dict['length_unit'] = atomman_input.get_value(v, 'length_unit', '') v_dict['pressure_unit'] = atomman_input.get_value(v, 'pressure_unit', '') v_dict['energy_unit'] = atomman_input.get_value(v, 'energy_unit', '') v_dict['force_unit'] = atomman_input.get_value(v, 'force_unit', '') v_dict['energy_tolerance'] = atomman_input.get_value( v, 'energy_tolerance', '') v_dict['force_tolerance'] = atomman_input.get_value( v, 'force_tolerance', '') v_dict['maximum_iterations'] = atomman_input.get_value( v, 'maximum_iterations', '') v_dict['maximum_evaluations'] = atomman_input.get_value( v, 'maximum_evaluations', '') #Check lengths of the multi-valued variables assert len(v.aslist('potential_file')) == len( v.aslist('potential_dir') ), 'potential_file and potential_dir must be of the same length' assert len(v.aslist('load')) == len(v.aslist( 'load_options')), 'load and load_options must be of the same length' assert len(v.aslist('load')) == len(v.aslist( 'load_elements')), 'load and load_elements must be of the same length' assert len(v.aslist('load')) == len( v.aslist('box_parameters' )), 'load and box_parameters must be of the same length' #Check that other variables are of at least length 1 if len(v.aslist('size_mults')) == 0: v['size_mults'] = '1 1 1' assert len(v.aslist('ptd_model')) > 0, 'no ptd_model found' #Read in terms #NO TERMS DEFINED FOR THIS CALCULATION #t = term_extractor(t, []) #v_dict[] = atomman_input.get_value(t, '', '') return run_directory, lib_directory, v_dict
def buildcontent(self, script, input_dict, results_dict=None): """ Builds a data model of the specified record style based on input (and results) parameters. Parameters ---------- script : str The name of the calculation script used. input_dict : dict Dictionary of all input parameter terms. results_dict : dict, optional Dictionary containing any results produced by the calculation. Returns ------- DataModelDict Data model consistent with the record's schema format. Raises ------ AttributeError If buildcontent is not defined for record style. """ # Build universal content super().buildcontent(script, input_dict, results_dict=results_dict) # Load content after root calc = self.content[self.contentroot] calc['calculation']['run-parameter'] = run_params = DM() # Copy over sizemults (rotations and shifts) subset('atomman_systemmanipulate').buildcontent( calc, input_dict, results_dict=results_dict) run_params['displacementdistance'] = uc.model( input_dict['displacementdistance'], input_dict['length_unit']) run_params['symmetryprecision'] = input_dict['symmetryprecision'] # Copy over potential data model info subset('lammps_potential').buildcontent(calc, input_dict, results_dict=results_dict) # Save info on system file loaded subset('atomman_systemload').buildcontent(calc, input_dict, results_dict=results_dict) if results_dict is None: calc['status'] = 'not calculated' else: pass
def build_model(self): """ Generates and returns model content based on the values set to object. """ # Build universal content model = super().build_model() calc = model[self.modelroot] # Build subset content self.commands.build_model(calc, after='atomman-version') self.potential.build_model(calc, after='calculation') self.system.build_model(calc, after='potential-LAMMPS') self.defect.build_model(calc, after='system-info') self.minimize.build_model(calc) self.elastic.build_model(calc) # Build calculation-specific content if 'calculation' not in calc: calc['calculation'] = DM() if 'run-parameter' not in calc['calculation']: calc['calculation']['run-parameter'] = DM() run_params = calc['calculation']['run-parameter'] run_params['dislocation_boundaryshape'] = self.boundaryshape run_params['dislocation_boundarywidth'] = self.boundarywidth run_params['dislocation_boundaryscale'] = self.boundaryscale run_params['annealtemperature'] = self.annealtemperature run_params['annealsteps'] = self.annealsteps # Build results if self.status == 'finished': calc['base-system'] = DM() calc['base-system']['artifact'] = DM() calc['base-system']['artifact']['file'] = self.dumpfile_base calc['base-system']['artifact']['format'] = 'atom_dump' calc['base-system']['symbols'] = self.symbols_base calc['defect-system'] = DM() calc['defect-system']['artifact'] = DM() calc['defect-system']['artifact']['file'] = self.dumpfile_defect calc['defect-system']['artifact']['format'] = 'atom_dump' calc['defect-system']['symbols'] = self.symbols_defect calc['defect-system']['potential-energy'] = uc.model( self.potential_energy_defect, self.units.energy_unit) calc['elastic-solution'] = elsol = DM() elsol['pre-ln-factor'] = uc.model( self.preln, f"{self.units.energy_unit}/{self.units.length_unit}") elsol['K-tensor'] = uc.model(self.K_tensor, self.units.pressure_unit) self._set_model(model) return model
def build_model(self, model, **kwargs): """ Adds the subset model to the parent model. Parameters ---------- model : DataModelDict.DataModelDict The record content (after root element) to add content to. kwargs : any Any options to pass on to dict_insert that specify where the subset content gets added to in the parent model. """ # Save defect parameters model[self.modelroot] = surf = DM() surf['key'] = self.key surf['id'] = self.id surf['system-family'] = self.family surf['calculation-parameter'] = cp = DM() if len(self.hkl) == 3: cp['hkl'] = f'{self.hkl[0]} {self.hkl[1]} {self.hkl[2]}' else: cp['hkl'] = f'{self.hkl[0]} {self.hkl[1]} {self.hkl[2]} {self.hkl[3]}' cp['shiftindex'] = str(self.shiftindex) cp['cutboxvector'] = self.cutboxvector cp['cellsetting'] = self.cellsetting # Build paths if needed if 'calculation' not in model: model['calculation'] = DM() if 'run-parameter' not in model['calculation']: model['calculation']['run-parameter'] = DM() run_params = model['calculation']['run-parameter'] run_params[f'{self.modelprefix}size-multipliers'] = DM() run_params[f'{self.modelprefix}size-multipliers']['a'] = sorted([0, self.sizemults[0]]) run_params[f'{self.modelprefix}size-multipliers']['b'] = sorted([0, self.sizemults[1]]) run_params[f'{self.modelprefix}size-multipliers']['c'] = sorted([0, self.sizemults[2]]) run_params[f'{self.modelprefix}minimum-width'] = uc.model(self.minwidth, self.parent.units.length_unit)
def build_model(self): """ Generates and returns model content based on the values set to object. """ # Build universal content model = super().build_model() calc = model[self.modelroot] # Build subset content self.commands.build_model(calc, after='atomman-version') self.potential.build_model(calc, after='calculation') self.system.build_model(calc, after='potential-LAMMPS') self.system_mods.build_model(calc) self.minimize.build_model(calc) # Build calculation-specific content if 'calculation' not in calc: calc['calculation'] = DM() if 'run-parameter' not in calc['calculation']: calc['calculation']['run-parameter'] = DM() run_params = calc['calculation']['run-parameter'] run_params['strain-range'] = self.strainrange # Build results if self.status == 'finished': cij = DM() cij['Cij'] = uc.model(self.raw_Cij_negative, self.units.pressure_unit) calc.append('raw-elastic-constants', cij) cij = DM() cij['Cij'] = uc.model(self.raw_Cij_positive, self.units.pressure_unit) calc.append('raw-elastic-constants', cij) calc['elastic-constants'] = DM() calc['elastic-constants']['Cij'] = uc.model(self.C.Cij, self.units.pressure_unit) self._set_model(model) return model
def asmodel(self): """ Returns the object info as data model content Returns ---------- DataModelDict: The data model content. """ # Initialize model model = DM() model['interatomic-potential'] = potential = DM() # Build identifiers potential['key'] = self.key potential['id'] = self.id potential['record-version'] = str(self.recorddate) # Build description potential['description'] = description = DM() for citation in self.citations: description.append('citation', citation.asmodel()['citation']) if self.notes is not None: description['notes'] = DM([('text', self.notes)]) # Build implementations for implementation in self.implementations: potential.append('implementation', implementation.asmodel()['implementation']) # Build element information if self.fictional: for element in self.elements: potential.append('fictional-element', element) else: for element in self.elements: potential.append('element', element) if self.othername is not None: potential['other-element'] = self.othername return model
def model(self, model=None, length_unit='angstrom'): """ Reads or generates a data model for the box. Parameters ---------- model : str or DataModelDict, optional JSON/XML formatted data, or path to file containing said data. If not given, then a model for the current box will be returned. length_unit : str, optional Unit of length to save box values in if data model is to be generated. Default value is 'angstrom'. Returns ------- DataModelDict.DataModelDict A JSON/XML equivalent data model for the box. Returned if model is not given """ # Set values if model given if model is not None: # Find box element model = DM(model).find('box') avect = uc.value_unit(model['avect']) bvect = uc.value_unit(model['bvect']) cvect = uc.value_unit(model['cvect']) origin = uc.value_unit(model['origin']) self.set(avect=avect, bvect=bvect, cvect=cvect, origin=origin) # Return DataModelDict if model not given else: model = DM() model['box'] = DM() model['box']['avect'] = uc.model(self.avect, length_unit) model['box']['bvect'] = uc.model(self.bvect, length_unit) model['box']['cvect'] = uc.model(self.cvect, length_unit) model['box']['origin']= uc.model(self.origin, length_unit) return model
def model(self, flatten=None): """ Returns an XML/JSON equivalent data mode of the information Parameters ---------- flatten : str or None, optional Specifies if the simulations are to be flattened, and which flatten style to use: - None does not flatten the simulations (default). - 'first' uses the values from the earliest simulation. - 'last' uses the values from the latest simulation. Returns ------- DataModelDict The Log content in data model form. """ if flatten is not None: self.flatten(flatten) # Create DataModelDict root log_model = DM() log_model['LAMMPS-log-thermo-data'] = DM() # Loop over all simulations for sim in self.simulations: sim_model = DM() # Convert to DataModelDict sim_model['thermo'] = DM() thermo = sim['thermo'] for j in thermo: sim_model['thermo'][str(j)] = thermo[j].values.tolist() # Append simulation results to DataModelDict root log_model['LAMMPS-log-thermo-data'].append('simulation', sim_model) return log_model
def build_citation(self, bib_database): """ Converts bibtex into xml description Parameters ---------- bib_database : bibtexparser.bibdatabase.BibDatabase Object containing bibtex data """ bib_dict = bib_database.entries[0] citation = DM() if bib_dict['ENTRYTYPE'] == 'article': citation['document-type'] = 'journal' citation['title'] = bib_dict['title'] citation['author'] = self.parse_authors(bib_dict['author']) citation['publication-name'] = bib_dict['journal'] citation['publication-date'] = DM() citation['publication-date']['year'] = bib_dict['year'] citation['volume'] = bib_dict['volume'] if 'number' in bib_dict: citation['issue'] = bib_dict['number'] elif 'issue' in bib_dict: citation['issue'] = bib_dict['issue'] if 'abstract' in bib_dict: citation['abstract'] = bib_dict['abstract'] if 'pages' in bib_dict: citation['pages'] = bib_dict['pages'].replace('--', '-') citation['DOI'] = bib_dict['doi'] elif bib_dict['ENTRYTYPE'] == 'unpublished': citation['document-type'] = 'unspecified' citation['title'] = bib_dict['title'] citation['author'] = self.parse_authors(bib_dict['author']) citation['publication-date'] = DM() citation['publication-date']['year'] = bib_dict['year'] citation['bibtex'] = bibtexparser.dumps(bib_database) return citation
def build_model(self): """ Generates and returns model content based on the values set to object. """ if len(self.symbols) is None: raise ValueError('symbols not set') # Build universal content model = super().build_model() calc = model[self.modelroot] # Build subset content self.commands.build_model(calc, after='atomman-version') self.potential.build_model(calc, after='calculation') # Build calculation-specific content if 'calculation' not in calc: calc['calculation'] = DM() if 'run-parameter' not in calc['calculation']: calc['calculation']['run-parameter'] = DM() calc['calculation']['run-parameter'] = run_params = DM() run_params['minimum_r'] = uc.model(self.minimum_r, self.units.length_unit) run_params['maximum_r'] = uc.model(self.maximum_r, self.units.length_unit) run_params['number_of_steps_r'] = self.number_of_steps_r dict_insert(calc, 'system-info', DM(), after='potential-LAMMPS') calc['system-info']['symbol'] = self.symbols # Build results if self.status == 'finished': calc['diatom-energy-relation'] = scan = DM() scan['r'] = uc.model(self.r_values, self.units.length_unit) scan['potential-energy'] = uc.model(self.energy_values, self.units.energy_unit) self._set_model(model) return model
def load(self, model): """" Loads the object info from data model content Parameters ---------- model : str or DataModelDict Model content or file path to model content. """ artifact = DM(model).find('artifact') self.url = artifact['web-link'].get('URL', None) self.label = artifact['web-link'].get('label', None) self.filename = artifact['web-link'].get('link-text', None)
def buildcontent(self, input_dict): """ Builds a data model of the specified record style based on input (and results) parameters. Parameters ---------- input_dict : dict Dictionary of all input parameter terms. Returns ------- DataModelDict Data model consistent with the record's schema format. Raises ------ AttributeError If buildcontent is not defined for record style. """ # Create the root of the DataModelDict output = DM() output[self.contentroot] = crystal = DM() # Assign key and id crystal['key'] = input_dict.get('key', str(uuid.uuid4())) crystal['id'] = input_dict['id'] # Specify source info crystal['source'] = DM() crystal['source']['name'] = input_dict['sourcename'] crystal['source']['link'] = input_dict['sourcelink'] system_model = input_dict['ucell'].dump('system_model', box_unit=input_dict.get( 'length_unit', None)) crystal['atomic-system'] = system_model['atomic-system'] self.content = output
def model(value, units=None, error=None): """ Generates DataModelDict representation of data. Parameters ---------- value : float, numpy.ndarray, etc. A numerical value or list/array of values. units : str The units to convert value to (from working units). error : float, numpy.ndarray, etc., optional A value error to include. If given, must be the same size/shape as value. Returns ------- DataModelDict Model representation of the value(s). """ datamodel = DM() if units is not None: value = get_in_units(value, units) if error is not None: error = get_in_units(error, units) # Single value if value.ndim == 0: datamodel['value'] = value if error is not None: datamodel['error'] = error # 1D array elif value.ndim == 1: datamodel['value'] = value.tolist() if error is not None: datamodel['error'] = error.tolist() # Higher-order array requires shape else: shape = value.shape datamodel['value'] = value.flatten().tolist() if error is not None: datamodel['error'] = error.flatten().tolist() datamodel['shape'] = list(shape) if units is not None: datamodel['unit'] = units return datamodel
def __init__(self, potential): """ Builds a PotInfo component class. Parameters ---------- potential : Potential, str or DataModelDict A Potential record object or DataModelDict contents for a Potential record. This prodives the information to link the Potential to the Action. """ if isinstance(potential, Potential.Potential): # Extract relevant properties from the Potential object self.__id = potential.id self.__key = potential.key self.__dois = [] for citation in potential.citations: try: self.__dois.append(citation.doi) except: pass self.__fictional = potential.fictional self.__elements = potential.elements self.__othername = potential.othername else: # Extract relevant properties from potential record contents model = DM(potential).find('potential') self.__id = model['id'] self.__key = model['key'] self.__dois = model.aslist('doi') felements = model.aslist('fictional-element') oelements = model.aslist('other-element') elements = model.aslist('element') if len(felements) > 0: assert len(elements) == 0 self.__fictional = True self.__elements = felements else: assert len(elements) > 0 self.__fictional = False self.__elements = elements if len(oelements) > 0: assert len(oelements) == 1 self.__othername = oelements[0] else: self.__othername = None
def asmodel(self): """ Builds data model (tree-like JSON/XML) representation for the potential. """ # Initialize model model = DM() model['interatomic-potential'] = potential = DM() # Build identifiers potential['key'] = self.key potential['id'] = self.id potential['record-version'] = str(self.recorddate) # Build description potential['description'] = description = DM() if self.developers is not None: description['developers'] = self.developers if self.year is not None: description['year'] = self.year if self.modelname is not None: description['model-name'] = self.modelname if self.dois is not None: for doi in self.dois: description.append('citation', DM([('DOI', doi)])) if self.notes is not None: description['notes'] = DM([('text', self.notes)]) # Build element information if self.fictional: for element in self.elements: potential.append('fictional-element', element) else: for element in self.elements: potential.append('element', element) if self.othername is not None: potential['other-element'] = self.othername return model
def build_model(self, model): if self.exists is True: model['point-defects'] = ec_model = DM() for composition in np.unique(self.data.composition): comp_results = self.data[self.data.composition == composition] # Build PotentialProperties data comp_model = DM() comp_model['composition'] = composition for prototype in np.unique(comp_results.prototype): proto_results = comp_results[comp_results.prototype == prototype] proto_model = DM() proto_model['prototype'] = prototype for alat in np.unique(proto_results.a): alat_records = proto_results[proto_results.a == alat] alat_model = DM() alat_model['a'] = alat for i in alat_records.sort_values(['E_f']).index: series = alat_records.loc[i] measurement = DM() measurement['pointdefect'] = series.pointdefect measurement['energy'] = series.E_f measurement['p11'] = series.pij[0, 0] measurement['p22'] = series.pij[1, 1] measurement['p33'] = series.pij[2, 2] measurement['p12'] = series.pij[0, 1] measurement['p13'] = series.pij[0, 2] measurement['p23'] = series.pij[1, 2] alat_model.append('measurement', measurement) proto_model.append('alats', alat_model) comp_model.append('prototypes', proto_model) ec_model.append('compositions', comp_model)
def add_parameter(implementation, line): """ Adds a parameter line to an implementation. Parameters ---------- implementation : DataModelDict The implementation sub-model of an interatomic-potential record to add a parameter line to. line : str The parameter line to add. """ parameter = DM() parameter['name'] = line implementation.append('parameter', parameter)
def parse_authors(self, authors): """ Parse bibtex authors field. Parameters ---------- authors : str bibtex-formatted author field. Returns ------- DataModelDict Data model of the parsed and separated names """ author_dicts = [] # remove ands from bib splAuth = authors.split(' and ') author = ' , '.join(splAuth) list_authors = author.split(' , ') #used for given/surname splitting for k in range(len(list_authors)): author_dict = DM() # if . is in initials, find the most right and strip given name and surname if '.' in list_authors[k]: l = list_authors[k].rindex(".") author_dict['given-name'] = list_authors[k][:l + 1].strip() author_dict['surname'] = list_authors[k][l + 1:].strip() # otherwise just split by the most right space else: l = list_authors[k].rindex(" ") author_dict['given-name'] = list_authors[k][:l + 1].strip() author_dict['surname'] = list_authors[k][l + 1:].strip() # Change given-name just into initials given = '' for letter in str(author_dict['given-name']).replace(' ', '').replace( '.', ''): if letter in string.ascii_uppercase: given += letter + '.' elif letter in ['-']: given += letter author_dict['given-name'] = given author_dicts.append(author_dict) return author_dicts
def build_model(self): """Builds parameters for atomman.defect.point()""" params = DM() params['ptd_type'] = self.ptd_type if self.atype is not None: params['atype'] = self.atype params[ 'pos'] = f'{self.pos[0]:.13} {self.pos[1]:.13} {self.pos[2]:.13}' if self.db_vect is not None: params[ 'db_vect'] = f'{self.db_vect[0]:.13} {self.db_vect[1]:.13} {self.db_vect[2]:.13}' params['scale'] = self.scale return params
def model(self, flatten=None): """Returns a DataModelDict containing the information.""" if flatten is not None: self.flatten(flatten) #Create DataModelDict root log_model = DM() log_model['LAMMPS-log-thermo-data'] = DM() #Loop over all simulations for sim in self.simulations: sim_model = DM() #Convert to DataModelDict sim_model['thermo'] = DM() thermo = sim['thermo'] for j in thermo: sim_model['thermo'][str(j)] = thermo[j].values.tolist() #Append simulation results to DataModelDict root log_model['LAMMPS-log-thermo-data'].append('simulation', sim_model) return log_model
def curate(self, content, title, template): """ Curates (uploads) a record to the MDCS instance. Parameters ---------- content : str The xml content or path to a file containing the content of the record to curate. title : str The name to assign to the record as it will be stored in the database. template : pandas.Series, str or dict, optional The template associated with the record. If str, will be searched against the template's id, title, and filename. If dict, allows multiple template parameters to be specified in matching correct template. """ # Handle template if isinstance(template, pd.Series): pass elif isinstance(template, dict): template = self.template_select_one(**template) else: template = self.template_select_one(template) # Check if matching record already curated records = self.select(title=title, template=template) if len(records) > 0: raise ValueError( 'Record with matching title and template already curated') # Handle content content = DM(content).xml() # Build requests parameters data = {} data['content'] = [content] data['schema'] = [template.id] data['title'] = [title] # Post and return response url = self.host + "/rest/curate" with warnings.catch_warnings(): warnings.simplefilter("ignore") r = requests.post(url, data=data, auth=(self.user, self.__pswd), verify=self.cert) r.raise_for_status()
def set_run_directory(name=None, path=None): """ Allows for run_directory information to be defined in the settings file. Parameters ---------- name : str, optional The name to assign to the run_directory. If not given, the user will be prompted to enter one. path : str, optional The directory path for the run_directory. If not given, the user will be prompted to enter one. """ # Get information from the settings file settings = load_settings() # Ask for name if not given if name is None: name = screen_input('Enter a name for the run_directory:') # Load run_directory if it exists try: run_directory_settings = settings.find('run_directory', yes={'name': name}) # Create new run_directory entry if it doesn't exist except: run_directory_settings = DM() settings['iprPy-defined-parameters'].append('run_directory', run_directory_settings) run_directory_settings['name'] = name # Ask if existing run_directory should be overwritten else: print(f'run_directory {name} already defined.') option = screen_input('Overwrite? (yes or no):') if option in ['yes', 'y']: pass elif option in ['no', 'n']: return None else: raise ValueError('Invalid choice') # Ask for path if not given if path is None: path = screen_input("Enter the run_directory's path:") run_directory_settings['path'] = Path(path).resolve().as_posix() save_settings(settings)
def build_model(self): """ Generates and returns model content based on the values set to object. """ # Initialize model model = DM() model['interatomic-potential'] = potential = DM() # Build identifiers potential['key'] = self.key potential['id'] = self.id potential['record-version'] = str(self.recorddate) # Build description potential['description'] = description = DM() for citation in self.citations: description.append('citation', citation.build_model()['citation']) if self.notes is not None: description['notes'] = DM([('text', self.notes)]) # Build implementations for implementation in self.implementations: potential.append('implementation', implementation.build_model()['implementation']) # Build element information if self.fictional: for element in self.elements: potential.append('fictional-element', element) else: for element in self.elements: potential.append('element', element) if self.othername is not None: potential['other-element'] = self.othername self._set_model(model) return model
def buildcontent(self, record_model, input_dict, results_dict=None): """ Converts the structured content to a simpler dictionary. Parameters ---------- record_model : DataModelDict.DataModelDict The record content (after root element) to add content to. input_dict : dict Dictionary of all input parameter terms. results_dict : dict, optional Dictionary containing any results produced by the calculation. """ prefix = self.prefix modelprefix = prefix.replace('_', '-') # Extract values keymap = self.keymap sizemults = input_dict[keymap['sizemults']] #atomshift = input_dict[keymap['atomshift']] #a_uvw = input_dict[keymap['a_uvw']] #b_uvw = input_dict[keymap['b_uvw']] #c_uvw = input_dict[keymap['c_uvw']] # Build paths if needed if 'calculation' not in record_model: record_model['calculation'] = DM() if 'run-parameter' not in record_model['calculation']: record_model['calculation']['run-parameter'] = DM() run_params = record_model['calculation']['run-parameter'] run_params[f'{modelprefix}size-multipliers'] = DM() run_params[f'{modelprefix}size-multipliers']['a'] = list(sizemults[0]) run_params[f'{modelprefix}size-multipliers']['b'] = list(sizemults[1]) run_params[f'{modelprefix}size-multipliers']['c'] = list(sizemults[2])
def buildcontent(self, record_model, input_dict, results_dict=None): """ Converts the structured content to a simpler dictionary. Parameters ---------- record_model : DataModelDict.DataModelDict The record content (after root element) to add content to. input_dict : dict Dictionary of all input parameter terms. results_dict : dict, optional Dictionary containing any results produced by the calculation. """ prefix = self.prefix modelprefix = prefix.replace('_', '-') record_model[f'{modelprefix}potential-LAMMPS'] = pot = DM() pot['key'] = input_dict[f'{prefix}potential'].key pot['id'] = input_dict[f'{prefix}potential'].id pot['potential'] = DM() pot['potential']['key'] = input_dict[f'{prefix}potential'].potkey pot['potential']['id'] = input_dict[f'{prefix}potential'].potid