Commit 2492c8cf authored by Berk Onat's avatar Berk Onat

Corrected convertUnits and add support to handle numpy arrays

parent 0e6743c8
......@@ -531,7 +531,9 @@ class AMBERParser(AmberC.AMBERParserBase):
if self.atompositions is not None:
self.trajRefSingleConfigurationCalculation = gIndex
SloppyBackend.addArrayValues('atom_positions', np.transpose(np.asarray(self.atompositions[0])))
SloppyBackend.addArrayValues('atom_positions', np.transpose(
np.asarray(self.metaStorage.convertUnits(self.atompositions[0], "Angstrom", self.unitDict)
)))
if self.topology is not None:
atom_labels = self.topologyDict["element"]
SloppyBackend.addArrayValues('atom_labels', np.asarray(atom_labels))
......@@ -728,10 +730,6 @@ class AMBERParser(AmberC.AMBERParserBase):
lastLine = parser.fIn.readline()
def build_mdinKeywordsSimpleMatchers(self):
cntrlDefVals={ 'x_amber_settings_integrator_type': 'molecular_dynamics',
'x_amber_settings_integrator_dt__ps': '0.001',
'x_amber_ensemble_type': 'NVE'
},
cntrlNameList=getList_MetaStrInDict(self.cntrlDict)
ewaldNameList=getList_MetaStrInDict(self.ewaldDict)
qmmmNameList=getList_MetaStrInDict(self.qmmmDict)
......
......@@ -280,23 +280,26 @@ class Container(object):
def convertUnits(self, updateValue, unit, unitdict):
if(isinstance(updateValue, list) or isinstance(updateValue, tuple)):
updateValue = [self.unitConverter(
ival, unit, unitdict
updateValue = [float(ival) * self.unitConverter(
unit, unitdict
) for ival in updateValue]
elif isinstance(updateValue, np.ndarray):
updateValue = np.asarray([self.unitConverter(
ival, unit, unitdict
) for ival in updateValue])
updateValue = updateValue * self.unitConverter(
unit, unitdict)
#updateValue = np.asarray([self.unitConverter(
# ival, unit, unitdict
# ) for ival in updateValue])
elif self.is_number(updateValue):
updateValue = self.convertToNumber(updateValue, "float")
updateValue = self.unitConverter(
updateValue, unit, unitdict)
updateValue = updateValue * self.unitConverter(
unit, unitdict)
else:
# I hope you know what you are doing
updateValue = self.unitConverter(
updateValue, unit, unitdict)
updateValue = float(updateValue) * self.unitConverter(
unit, unitdict)
return updateValue
def unitConverter(self, updateValue, unit, unitdict):
def unitConverter(self, unit, unitdict):
""" Unit converter using definitions of units explicitly
The unit names are converted to numbers and the resulting
......@@ -312,7 +315,7 @@ class Container(object):
newunit = newunit.replace('-','*').replace(' ', '*').replace('^', "**")
for key,value in unitdict.items():
newunit = newunit.replace(str(key), str(value))
return float(updateValue) * float(eval(newunit))
return float(eval(newunit))
def checkTestsDicts(self, item, localdict):
for depdict in item["depends"]:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment