def _init_parameter_names(self): self.symbol_pairs = list(determine_symbol_pairs(self.symbols)) self.parameter_names = [] for s in self.symbol_pairs: for p in self.pair_parameter_names: self.parameter_names.append(self.PYPOSPACK_PAIR_FORMAT.format(s1=s[0], s2=s[1], p=p)) return list(self.parameter_names)
def test__1_symbol(): from pypospack.potential import determine_symbol_pairs symbols = ['Ni'] pairs = determine_symbol_pairs(symbols) assert type(pairs) is list assert len(pairs) == 1 assert pairs[0] == ['Ni', 'Ni']
def test__2_symbols(): from pypospack.potential import determine_symbol_pairs symbols = ['Mg', 'O'] expected_pairs = [['Mg', 'Mg'], ['Mg', 'O'], ['O', 'O']] pairs = determine_symbol_pairs(symbols) assert type(pairs) is list assert pairs == expected_pairs assert pairs[0] == ['Mg', 'Mg'] assert pairs[1] == ['Mg', 'O'] assert pairs[2] == ['O', 'O'] assert len(pairs) == 3
def _init_parameter_names(self): self.symbol_pairs = list(determine_symbol_pairs(self.symbols)) self.parameter_names = [] for s in self.symbols: self.parameter_names.append(self.PYPOSPACK_CHRG_FORMAT.format(s=s)) for sp in self.symbol_pairs: for p in self.PAIR_POTENTIAL_PARAMETERS: self.parameter_names.append( self.PYPOSPACK_PAIR_FORMAT.format(s1=sp[0], s2=sp[1], p=p)) return list(self.parameter_names)
def initialize_parameter_names(self,symbols=None): if symbols is None: symbols = self.symbols self.symbol_pairs = list(determine_symbol_pairs(symbols)) # initialize attribute to populate self.parameter_names = [] if self.is_charge: for s in self.symbols: fmt = self.PYPOSPACK_CHRG_FORMAT self.parameter_names.append(fmt.format(s=s)) for sp in self.symbol_pairs: for p in self.pair_potential_parameters: fmt = self.PYPOSPACK_PAIR_FORMAT self.parameter_names.append(fmt.format(s1=sp[0],s2=sp[1],p=p)) return self.parameter_names
def test__determine_symbol_pairs(symbols, symbol_pairs): assert symbol_pairs == determine_symbol_pairs(symbols=symbols)
import pytest from pypospack.potential import determine_symbol_pairs test_sets = [('Ni', [['Ni', 'Ni']]), (['Ni'], [['Ni', 'Ni']]), (['Ni', 'Al'], [['Ni', 'Ni'], ['Ni', 'Al'], ['Al', 'Al']])] test_ids = ['Ni_str', 'Ni_list', 'NiAl_list'] @pytest.mark.parametrize('symbols,symbol_pairs', test_sets, ids=test_ids) def test__determine_symbol_pairs(symbols, symbol_pairs): assert symbol_pairs == determine_symbol_pairs(symbols=symbols) if __name__ == "__main__": symbols = ['Ni'] symbol_pairs = determine_symbol_pairs(symbols=symbols) print(symbol_pairs)