Skip to content

Commit

Permalink
average same terms
Browse files Browse the repository at this point in the history
  • Loading branch information
MFSJMenger committed Oct 5, 2024
1 parent 9d12303 commit 0918460
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def compute_rmsd(logger, mol, structs):
class Fitter:

def __init__(self, mol, equfits=['bond']):
self.equfits = equfits
self.mol = deepcopy(mol)
self.parameters = self._get_fitparameters(equfits)

Expand All @@ -266,8 +267,39 @@ def _get_fitparameters(self, equfits):
if values is not None:
values.append(term)


for terms in self.averagize_parameters(equfits).values():
if len(terms) == 1:
continue

# assume that its just one constant!!!!
constants = [term.constants()[0] for term in terms]
start = constants[0]

values = []
for constant in constants:
values += parameters[constant]
del parameters[constant]

parameters[start] = values

return parameters

def averagize_parameters(self, equfits):
# not sure if it should be done or not
sorted_terms = {}

for termcls in equfits:
for term in self.mol.terms[termcls]:
name = str(term)
values = sorted_terms.get(name)
if values is None:
sorted_terms[name] = [term]
else:
values.append(term)

return sorted_terms

def optimize(self, logger, structs):

# assume ordered dictionaries!
Expand Down Expand Up @@ -295,7 +327,7 @@ def _helper(values):
print("start_values = ", start_values)

for _ in range(20):
# do first multi_fit
# do first multi_fit
res = minimize(_helper, start_values) # method='Powell')
start_values = res.x
multi_fit(logger, mol, structs)
Expand Down

0 comments on commit 0918460

Please sign in to comment.