rem
stringlengths 0
322k
| add
stringlengths 0
2.05M
| context
stringlengths 8
228k
|
---|---|---|
self.vars = self.vars_stack[-1] | self.vars.update(self.vars_stack[-1]) | def pop_vars (self): """ Restore the last set of variables saved using "push_vars". """ self.vars = self.vars_stack[-1] del self.vars_stack[-1] |
if not self.expand_needed(): return 0 | def run (self): if not self.expand_needed(): return 0 self.msg(0, _("writing %s...") % (self.out)) self.out_stream = open(self.out, "w") try: self.expand_path(self.env.source()) except rubber.EndDocument: self.out_stream.write("\\end{document}\n") self.out_stream.close() self.env.something_done = 1 |
|
try: self.expand_path(self.env.source()) except rubber.EndDocument: self.out_stream.write("\\end{document}\n") self.out_stream.close() self.env.something_done = 1 def expand_needed (self): """ Check if running epxanding the source is needed. """ final = self.env.src_base + "-final.tex" if not exists(final): self.msg(3, _("the expanded file doesn't exist")) return 1 if getmtime(final) < getmtime(self.env.src_base + ".dvi"): self.msg(3, _("the expanded file is older than the DVI")) return 1 self.msg(3, _("expansion is not needed")) return 0 def expand_path (self, path): file = open(path) | def run (self): if not self.expand_needed(): return 0 self.msg(0, _("writing %s...") % (self.out)) self.out_stream = open(self.out, "w") try: self.expand_path(self.env.source()) except rubber.EndDocument: self.out_stream.write("\\end{document}\n") self.out_stream.close() self.env.something_done = 1 |
|
self.env.do_process(file, path, dump=self.out_stream) | try: self.expand_path(self.env.source()) except rubber.EndDocument: self.out_stream.write("\\end{document}\n") | def expand_path (self, path): # self.out_stream.write("%%--- beginning of file %s\n" % path) file = open(path) |
return 0 | continue | def main (self, cmdline): """ Run Rubber for the specified command line. This processes each specified source in order (for making or cleaning). If an error happens while making one of the documents, the whole process stops. The method returns the program's exit code. """ self.prologue = [] self.epilogue = [] self.clean = 0 self.force = 0 |
self.conf = Config() | def __init__ (self, message): """ Initialize the environment. This prepares the processing steps for the given file (all steps are initialized empty) and sets the regular expressions and the hook dictionary. """ self.msg = message self.msg(2, _("initializing Rubber...")) |
|
self.msg(1, _("initializing...")) | self.msg(1, _("reinitializing...")) | def restart (self): """ Reinitialize the environment, in order to process a new document. This resets the process and the hook dictionary and unloads modules. """ self.msg(1, _("initializing...")) self.modules.clear() self.initialize() |
self.modules.register("bibtex", dict) for db in dict["arg"].split(","): self.modules["bibtex"].add_db(db) | if dict["arg"]: self.modules.register("bibtex", dict) for db in dict["arg"].split(","): self.modules["bibtex"].add_db(db) | def h_bibliography (self, dict): """ Called when the macro \\bibliography is found. This method actually registers the module bibtex (if not already done) and registers the databases. """ self.modules.register("bibtex", dict) for db in dict["arg"].split(","): self.modules["bibtex"].add_db(db) |
self.modules.register("bibtex", dict) self.modules["bibtex"].set_style(dict["arg"]) | if dict["arg"]: self.modules.register("bibtex", dict) self.modules["bibtex"].set_style(dict["arg"]) | def h_bibliographystyle (self, dict): """ Called when \\bibliographystyle is found. This registers the module bibtex (if not already done) and calls the method set_style() of the module. """ self.modules.register("bibtex", dict) self.modules["bibtex"].set_style(dict["arg"]) |
if self.src_path != "": | if self.src_path == "": self.src_path = "." else: | def set_source (self, path): """ Specify the main source for the document. The exact path and file name are determined, and the source building process is updated if needed, according the the source file's extension. """ name = self.conf.find_input(path) if not name: self.msg(0, _("cannot find %s") % path) return 1 self.depends = {} (self.src_path, name) = split(name) if self.src_path != "": self.conf.path.append(self.src_path) (self.src_base, self.src_ext) = splitext(name) self.src_pbase = join(self.src_path, self.src_base) |
saved = {} | saved = self.vars.copy() | def push_vars (self, **dict): """ For each named argument "key=val", save the value of variable "key" and assign it the value "val". """ saved = {} for (key, val) in dict.items(): saved[key] = self.vars[key] self.vars[key] = val self.vars_stack.append(saved) |
saved[key] = self.vars[key] | def push_vars (self, **dict): """ For each named argument "key=val", save the value of variable "key" and assign it the value "val". """ saved = {} for (key, val) in dict.items(): saved[key] = self.vars[key] self.vars[key] = val self.vars_stack.append(saved) |
|
self.vars.update(self.vars_stack[-1]) | self.vars = self.vars_stack[-1] | def pop_vars (self): """ Restore the last set of variables saved using "push_vars". """ self.vars.update(self.vars_stack[-1]) del self.vars_stack[-1] |
self.cwd = join(curdir, "") | self.cwd = "./" | def __init__ (self, level=1, write=None): """ Initialize the object with the specified verbosity level and an optional writing function. If no such function is specified, no message will be output until the 'write' field is changed. """ self.level = level self.write = write self.short = 0 self.path = "" self.cwd = join(curdir, "") |
rule = dict(cp.items(name)) | rule = {} for key in cp.options(name): rule[key] = cp.get(name, key) | def read_ini (self, filename): """ Read a set of rules from a file. See the texinfo documentation for the expected format of this file. """ from ConfigParser import ConfigParser cp = ConfigParser() cp.read(filename) for name in cp.sections(): rule = dict(cp.items(name)) rule["cost"] = cost = cp.getint(name, "cost") expr = re.compile(rule["target"] + "$") self.rules[name] = (expr, cost, rule) |
that no compilatin was done (by the script) yet. | that no compilation was done (by the script) yet. | def compile_needed (self): """ Returns true if a first compilation is needed. This method supposes that no compilatin was done (by the script) yet. """ if self.must_compile: return 1 self.msg(3, _("checking if compiling is necessary...")) if not exists(self.src_base + self.out_ext): self.msg(3, _("the output file doesn't exist")) return 1 if not exists(self.src_base + ".log"): self.msg(3, _("the log file does not exist")) return 1 if getmtime(self.src_base + ".log") < getmtime(self.source()): self.msg(3, _("the source is younger than the log file")) return 1 if self.log.read(self.src_base + ".log"): self.msg(3, _("the log file is not produced by %s") % self.conf.tex) return 1 return self.recompile_needed() |
return string.find(line, "warning:") != -1 | if string.find(line, "warning:") == -1: return 1 | def errors (self): """ Returns true if there was an error during the compilation. """ for line in self.lines: if line[0] == "!": # We check for the substring "warning:" because pdfTeX # sometimes issues warnings (like undefined references) in the # form of errors... |
values += self.canonicalize(arg) | values += canonicalize(arg) | def canonicalize(args): """ BootAuth canonicalization method. Parameter values are collected, sorted, converted to strings, then hashed with the node key. """ |
values += self.canonicalize(arg.values()) | values += canonicalize(arg.values()) | def canonicalize(args): """ BootAuth canonicalization method. Parameter values are collected, sorted, converted to strings, then hashed with the node key. """ |
if old_rec != None and rec['timestamp'] > old_rec['timestamp']: | if old_rec == None: self[name] = rec elif rec['timestamp'] > old_rec['timestamp']: | def deliver_record(self, rec): """A record is simply a dictionary with 'name' and 'timestamp' keys. We keep some persistent private data in the records under keys that start with '_'; thus record updates should not displace such keys.""" name = rec['name'] old_rec = self.get(name) if old_rec != None and rec['timestamp'] > old_rec['timestamp']: for key in old_rec.keys(): if not key.startswith('_'): del old_rec[key] old_rec.update(rec) elif rec['timestamp'] >= self._min_timestamp: self[name] = rec |
elif rec['timestamp'] >= self._min_timestamp: self[name] = rec | def deliver_record(self, rec): """A record is simply a dictionary with 'name' and 'timestamp' keys. We keep some persistent private data in the records under keys that start with '_'; thus record updates should not displace such keys.""" name = rec['name'] old_rec = self.get(name) if old_rec != None and rec['timestamp'] > old_rec['timestamp']: for key in old_rec.keys(): if not key.startswith('_'): del old_rec[key] old_rec.update(rec) elif rec['timestamp'] >= self._min_timestamp: self[name] = rec |
|
if self.system(cf_rec['postinstall_cmd']): system(err_cmd) | if self.system(cf_rec['postinstall_cmd']): self.system(err_cmd) | def update_conf_file(self, cf_rec): if not cf_rec['enabled']: return dest = cf_rec['dest'] logger.log('conf_files: considering file %s' % dest) err_cmd = cf_rec['error_cmd'] mode = string.atoi(cf_rec['file_permissions'], base=8) uid = pwd.getpwnam(cf_rec['file_owner'])[2] gid = grp.getgrnam(cf_rec['file_group'])[2] url = 'https://%s/%s' % (self.config.PLC_BOOT_HOST, cf_rec['source']) contents = curlwrapper.retrieve(url) logger.log('conf_files: retrieving url %s' % url) if not cf_rec['always_update'] and sha.new(contents).digest() == self.checksum(dest): logger.log('conf_files: skipping file %s, always_update is false and checksums are identical' % dest) return if self.system(cf_rec['preinstall_cmd']): self.system(err_cmd) if not cf_rec['ignore_cmd_errors']: return logger.log('conf_files: installing file %s' % dest) tools.write_file(dest, lambda f: f.write(contents), mode=mode, uidgid=(uid,gid)) if self.system(cf_rec['postinstall_cmd']): system(err_cmd) |
function = function.replace('.', '/') | function = function.split('.') | def processInputs(self): 'See IPublisherRequest' |
self.setPathSuffix((function,)) | self.setPathSuffix(function) | def processInputs(self): 'See IPublisherRequest' |
except Exception, e: self.handleException(e) | except: self.handleException(sys.exc_info()) | def setBody(self, body): """Sets the body of the response |
import traceback traceback.print_tb(exc_info[2]) print t print value | def handleException(self, exc_info): """Handle Errors during publsihing and wrap it in XML-RPC XML""" t, value = exc_info[:2] |
|
if self._charset is not None and isinstance(text, unicode): return text.encode(self._charset) | if isinstance(text, unicode): return text.encode(self._charset or 'UTF-8') | def _encode(self, text): if self._charset is not None and isinstance(text, unicode): return text.encode(self._charset) return text |
self._args, function = xmlrpclib.loads(self._body_instream.read()) | lines = ''.join(self._body_instream.readlines()) self._args, function = xmlrpclib.loads(lines) | def processInputs(self): 'See IPublisherRequest' |
publication = Attribute("""the request's publication object | publication = Attribute("""The request's publication object | def retry(): """Return a retry request |
body = Attribute("""the body of the request as a string""") bodyFile = Attribute("""the body of the request as a file""") | body = Attribute("""The body of the request as a string""") bodyFile = Attribute("""The body of the request as a file""") | def processInputs(): """Do any input processing that needs to bve done before traversing |
The only request data are envirnment variables. | The only request data are environment variables. | def __getitem__(key): """Return request data |
data = self.stream.readline(size) | data = self.stream.readline() | def readline(self, size=None): data = self.stream.readline(size) self.cacheStream.write(data) return data |
self.test_IApplicationRequest_bodyStream | self.test_IApplicationRequest_body | def testHaveCustomTestsForIApplicationRequest(self): # Make sure that tests are defined for things we can't test here self.test_IApplicationRequest_bodyStream |
auth=self._auth if auth: if auth.lower().startswith('basic '): if base64 is None: import base64 | if self._auth: if self._auth.lower().startswith('basic '): if base64 is None: import base64 | def _authUserPW(self): 'See IHTTPCredentials' global base64 auth=self._auth if auth: if auth.lower().startswith('basic '): if base64 is None: import base64 name, password = base64.decodestring( auth.split()[-1]).split(':') return name, password |
auth.split()[-1]).split(':') | self._auth.split()[-1]).split(':') | def _authUserPW(self): 'See IHTTPCredentials' global base64 auth=self._auth if auth: if auth.lower().startswith('basic '): if base64 is None: import base64 name, password = base64.decodestring( auth.split()[-1]).split(':') return name, password |
def _updateContentLength(self): blen = str(len(self._body)) | def _updateContentLength(self, data=None): if data is None: blen = str(len(self._body)) else: blen = str(len(data)) | def _updateContentLength(self): blen = str(len(self._body)) if blen.endswith('L'): blen = blen[:-1] self.setHeader('content-length', blen) |
cookies on the response object. | cookies on the response object and encode the string into appropriate encoding. | def write(self, string): """See IApplicationResponse |
if self.getHeader('content-type', '').startswith('text'): data = self._encode(data) self._updateContentLength(data) | def output(self, data): """Output the data to the world. There are a couple of steps we have to do: |
|
if self.getHeader('content-type', '').startswith('text'): data = self._encode(data) | def output(self, data): """Output the data to the world. There are a couple of steps we have to do: |
|
self.pres = Presentation() | self.pres = Presentation(ContentStub(), TestRequest()) | def setUp(self): self.pres = Presentation() |
self.filename = aFieldStorage.filename | self.filename = unicode(aFieldStorage.filename, 'UTF-8') | def __init__(self, aFieldStorage): |
"XMLRPC View" | def getDefaultTraversal(request, ob): """Get the default published object for the request |
|
(item.filename is not None | (item.filename is not None and item.filename != '' | def processInputs(self): 'See IPublisherRequest' |
eq(locale.getLocaleLanguageId(), lang) eq(locale.getLocaleCountryId(), country) eq(locale.getLocaleVariantId(), variant) | eq(locale.id.language, lang) eq(locale.id.country, country) eq(locale.id.variant, variant) | def testRequestLocale(self): eq = self.assertEqual unless = self.failUnless for httplang in ('it', 'it-ch', 'it-CH', 'IT', 'IT-CH', 'IT-ch'): req = self._createRequest({'HTTP_ACCEPT_LANGUAGE': httplang}) locale = req.getLocale() unless(ILocale.isImplementedBy(locale)) parts = httplang.split('-') lang = parts.pop(0).lower() country = variant = None if parts: country = parts.pop(0).upper() if parts: variant = parts.pop(0).upper() eq(locale.getLocaleLanguageId(), lang) eq(locale.getLocaleCountryId(), country) eq(locale.getLocaleVariantId(), variant) # Now test for non-existant locale fallback req = self._createRequest({'HTTP_ACCEPT_LANGUAGE': 'xx'}) locale = req.getLocale() unless(ILocale.isImplementedBy(locale)) eq(locale.getLocaleLanguageId(), None) eq(locale.getLocaleCountryId(), None) eq(locale.getLocaleVariantId(), None) |
eq(locale.getLocaleLanguageId(), None) eq(locale.getLocaleCountryId(), None) eq(locale.getLocaleVariantId(), None) | eq(locale.id.language, None) eq(locale.id.country, None) eq(locale.id.variant, None) | def testRequestLocale(self): eq = self.assertEqual unless = self.failUnless for httplang in ('it', 'it-ch', 'it-CH', 'IT', 'IT-CH', 'IT-ch'): req = self._createRequest({'HTTP_ACCEPT_LANGUAGE': httplang}) locale = req.getLocale() unless(ILocale.isImplementedBy(locale)) parts = httplang.split('-') lang = parts.pop(0).lower() country = variant = None if parts: country = parts.pop(0).upper() if parts: variant = parts.pop(0).upper() eq(locale.getLocaleLanguageId(), lang) eq(locale.getLocaleCountryId(), country) eq(locale.getLocaleVariantId(), variant) # Now test for non-existant locale fallback req = self._createRequest({'HTTP_ACCEPT_LANGUAGE': 'xx'}) locale = req.getLocale() unless(ILocale.isImplementedBy(locale)) eq(locale.getLocaleLanguageId(), None) eq(locale.getLocaleCountryId(), None) eq(locale.getLocaleVariantId(), None) |
path = self.get("PATH_INFO", "/") path = unquote(path) path = path.decode('UTF-8') self._environ["PATH_INFO"] = path | def __setupPath(self): # The recommendation states that: # # Unless there is some compelling reason for a # particular scheme to do otherwise, translating character sequences # into UTF-8 (RFC 2279) [3] and then subsequently using the %HH # encoding for unsafe octets is recommended. # # See: http://www.ietf.org/rfc/rfc2718.txt, Section 2.2.5 path = self.get("PATH_INFO", "/") path = unquote(path) path = path.decode('UTF-8') self._environ["PATH_INFO"] = path self._setupPath_helper("PATH_INFO") |
|
def IPublisher(Interface): | class IPublisher(Interface): | def IPublisher(Interface): def publish(request): """Publish a request The request must be an IPublisherRequest. """ |
response.setCharset() | response.setCharset(charset) | def _getResultFromResponse(self, body, charset=None, headers=None): response, stream = self._createResponse() if charset is not None: response.setCharset() if headers is not None: for hdr, val in headers.iteritems(): response.setHeader(hdr, val) response.setBody(body) response.outputBody() return self._parseResult(stream.getvalue()) |
"""Do any input processing that needs to bve done before traversing | """Do any input processing that needs to be done before traversing | def processInputs(): """Do any input processing that needs to bve done before traversing |
raise Unauthorized("Name %s begins with an underscore" % `name`) | raise Unauthorized, name | def traverseName(self, request, ob, name, check_auth=1): if name.startswith('_'): raise Unauthorized("Name %s begins with an underscore" % `name`) if hasattr(ob, name): subob = getattr(ob, name) else: try: subob = ob[name] except (KeyError, IndexError, TypeError, AttributeError): raise NotFound(ob, name, request) if self.require_docstrings and not getattr(subob, '__doc__', None): raise DebugError(subob, 'Missing or empty doc string') return subob |
'''Effect persistent side-effects. | """Effect persistent side-effects. | def __call__(obj, request, exc_info): '''Effect persistent side-effects. |
''' | """ | def __call__(obj, request, exc_info): '''Effect persistent side-effects. |
inittime = int(time()) | fullinittime = time() inittime = int(fullinittime) | def getobsc(snum,stime,observables,zerotime=0.0): inittime = int(time()) lasttime = 0 print "Processing...", sys.stdout.flush() try: if len(Numeric.shape(observables)) == 0: array = Numeric.zeros(snum,typecode='d') for i in Numeric.arange(0,snum): array[i] = observables(zerotime+i*stime) if i % 1024 == 0: lasttime = dotime(i,snum,inittime,lasttime) else: obslen = Numeric.shape(observables)[0] array = Numeric.zeros((snum,obslen),typecode='d') for i in Numeric.arange(0,snum): for j in range(0,obslen): array[i,j] = observables[j](zerotime+i*stime) if i % 1024 == 0: lasttime = dotime(i,snum,inittime,lasttime) except IndexError: print "lisautils::getobsc: I have trouble accessing time ", zerotime+i*stime, print "; you may try to reset your objects and repeat..." raise # there was good stuff here, but it's better to let the user deal with this # in particular, if observables is a noise-like variable, then it should # have the 'reset' method ['reset' in dir(observables)]; if observables is # a method of a TDI class, which should have the 'reset' method, the test # is ['reset' in dir(observables.im_self)], where "im_self" returns the # class instance for a given instance method currenttime = int(time()) - inittime if currenttime > 0: vel = ((1.0*snum)/currenttime) print "\r...completed in %d s [%d (multi)samples/s]. " % (currenttime,vel) else: print "\r...completed. " return array |
currenttime = int(time()) - inittime | currenttime = time() - fullinittime | def getobsc(snum,stime,observables,zerotime=0.0): inittime = int(time()) lasttime = 0 print "Processing...", sys.stdout.flush() try: if len(Numeric.shape(observables)) == 0: array = Numeric.zeros(snum,typecode='d') for i in Numeric.arange(0,snum): array[i] = observables(zerotime+i*stime) if i % 1024 == 0: lasttime = dotime(i,snum,inittime,lasttime) else: obslen = Numeric.shape(observables)[0] array = Numeric.zeros((snum,obslen),typecode='d') for i in Numeric.arange(0,snum): for j in range(0,obslen): array[i,j] = observables[j](zerotime+i*stime) if i % 1024 == 0: lasttime = dotime(i,snum,inittime,lasttime) except IndexError: print "lisautils::getobsc: I have trouble accessing time ", zerotime+i*stime, print "; you may try to reset your objects and repeat..." raise # there was good stuff here, but it's better to let the user deal with this # in particular, if observables is a noise-like variable, then it should # have the 'reset' method ['reset' in dir(observables)]; if observables is # a method of a TDI class, which should have the 'reset' method, the test # is ['reset' in dir(observables.im_self)], where "im_self" returns the # class instance for a given instance method currenttime = int(time()) - inittime if currenttime > 0: vel = ((1.0*snum)/currenttime) print "\r...completed in %d s [%d (multi)samples/s]. " % (currenttime,vel) else: print "\r...completed. " return array |
vel = ((1.0*snum)/currenttime) print "\r...completed in %d s [%d (multi)samples/s]. " % (currenttime,vel) | vel = snum/currenttime print "\r...completed in %d s [%d (multi)samples/s]. " % (int(currenttime),int(vel)) | def getobsc(snum,stime,observables,zerotime=0.0): inittime = int(time()) lasttime = 0 print "Processing...", sys.stdout.flush() try: if len(Numeric.shape(observables)) == 0: array = Numeric.zeros(snum,typecode='d') for i in Numeric.arange(0,snum): array[i] = observables(zerotime+i*stime) if i % 1024 == 0: lasttime = dotime(i,snum,inittime,lasttime) else: obslen = Numeric.shape(observables)[0] array = Numeric.zeros((snum,obslen),typecode='d') for i in Numeric.arange(0,snum): for j in range(0,obslen): array[i,j] = observables[j](zerotime+i*stime) if i % 1024 == 0: lasttime = dotime(i,snum,inittime,lasttime) except IndexError: print "lisautils::getobsc: I have trouble accessing time ", zerotime+i*stime, print "; you may try to reset your objects and repeat..." raise # there was good stuff here, but it's better to let the user deal with this # in particular, if observables is a noise-like variable, then it should # have the 'reset' method ['reset' in dir(observables)]; if observables is # a method of a TDI class, which should have the 'reset' method, the test # is ['reset' in dir(observables.im_self)], where "im_self" returns the # class instance for a given instance method currenttime = int(time()) - inittime if currenttime > 0: vel = ((1.0*snum)/currenttime) print "\r...completed in %d s [%d (multi)samples/s]. " % (currenttime,vel) else: print "\r...completed. " return array |
if currenttime - lasttime > 2: | if currenttime - lasttime > 2 and i > 0: | def dotime(i,snum,inittime,lasttime): currenttime = int(time()) - inittime if currenttime - lasttime > 2: percdone = int((100.0*i)/snum) timeleft = int(((1.0 * currenttime) / i) * (snum-i)) vel = ((1.0*i)/currenttime) minleft = timeleft / 60 secleft = timeleft - minleft*60 print "\r...%d/%d (%d%%) done [%d (multi)samples/s], est. %dm%ds left..." % (i,snum,percdone,vel,minleft,secleft), sys.stdout.flush() return currenttime return lasttime |
def spect(series,sampling,patches=1,detrend=0): | def spect(series,sampling,patches=1,detrend=0,overlap=1): | def spect(series,sampling,patches=1,detrend=0): nyquistf = 0.5 / sampling if patches==0: period = pdg(series) elif patches==1: period = wpdg(series,detrend) else: period = opwpdg(series,patches,detrend) pdlen = shape(period)[0]-1 freqs = arange(0,pdlen+1,typecode='d') * (nyquistf / pdlen) deltaf = nyquistf / pdlen period[0] = 2 * period[0] / deltaf period[1:pdlen] = period[1:pdlen] / deltaf period[pdlen] = 2 * period[pdlen] / deltaf spectrum = zeros((pdlen+1,2),typecode='d') spectrum[:,0] = freqs[:] spectrum[:,1] = period[:] return spectrum |
period = opwpdg(series,patches,detrend) | if overlap==0: period = nopwpdg(series,patches,detrend) else: period = opwpdg(series,patches,detrend) | def spect(series,sampling,patches=1,detrend=0): nyquistf = 0.5 / sampling if patches==0: period = pdg(series) elif patches==1: period = wpdg(series,detrend) else: period = opwpdg(series,patches,detrend) pdlen = shape(period)[0]-1 freqs = arange(0,pdlen+1,typecode='d') * (nyquistf / pdlen) deltaf = nyquistf / pdlen period[0] = 2 * period[0] / deltaf period[1:pdlen] = period[1:pdlen] / deltaf period[pdlen] = 2 * period[pdlen] / deltaf spectrum = zeros((pdlen+1,2),typecode='d') spectrum[:,0] = freqs[:] spectrum[:,1] = period[:] return spectrum |
pdlen = samples/2 | pdlen = (samples-1)/2.0 | def wpdg(series,detrend=0): samples = shape(series)[0] pdlen = samples/2 window = 1.0 - abs(arange(0,samples,typecode='d') - pdlen) / (pdlen) weight = samples * sum(window ** 2) # detrending if detrend==0: mean = 0.0 else: mean = sum(series) / (1.0*samples) wseries = window * (series - mean) wpdgram = pdg(wseries) * (1.0 * samples**2 / weight) return wpdgram |
def nopwpdg(series,patches,detrend=0): samples = shape(series)[0] serlen = samples - (samples % (4*patches)) patlen = serlen/patches pdlen = patlen/2 opwpdgram = zeros(pdlen+1,typecode='d') for cnt in range(0,patches): opwpdgram[:] += wpdg(series[cnt*patlen:(cnt+1)*patlen],detrend) opwpdgram[:] /= 1.0*patches return opwpdgram | def opwpdg(series,patches,detrend=0): samples = shape(series)[0] serlen = samples - (samples % (4*patches)) patlen = serlen/patches pdlen = patlen/2 opwpdgram = zeros(pdlen+1,typecode='d') for cnt in range(0,2*patches-1): opwpdgram[:] += wpdg(series[cnt*pdlen:(cnt+2)*pdlen],detrend) opwpdgram[:] /= (2.0*patches - 1.0) return opwpdgram |
|
def getobs(snum,stime,observables): | def getobs(snum,stime,observables,zerotime=0.0): | def getobs(snum,stime,observables): if len(shape(observables)) == 0: array = zeros(snum,typecode='d') for i in arange(0,snum): array[i] = observables(i*stime) else: obslen = shape(observables)[0] array = zeros((snum,obslen),typecode='d') for i in arange(0,snum): for j in range(0,obslen): array[i,j] = observables[j](i*stime) return array |
array[i] = observables(i*stime) | array[i] = observables(zerotime+i*stime) | def getobs(snum,stime,observables): if len(shape(observables)) == 0: array = zeros(snum,typecode='d') for i in arange(0,snum): array[i] = observables(i*stime) else: obslen = shape(observables)[0] array = zeros((snum,obslen),typecode='d') for i in arange(0,snum): for j in range(0,obslen): array[i,j] = observables[j](i*stime) return array |
array[i,j] = observables[j](i*stime) | array[i,j] = observables[j](zerotime+i*stime) | def getobs(snum,stime,observables): if len(shape(observables)) == 0: array = zeros(snum,typecode='d') for i in arange(0,snum): array[i] = observables(i*stime) else: obslen = shape(observables)[0] array = zeros((snum,obslen),typecode='d') for i in arange(0,snum): for j in range(0,obslen): array[i,j] = observables[j](i*stime) return array |
def getobsc(snum,stime,observables): | def getobsc(snum,stime,observables,zerotime=0.0): | def getobsc(snum,stime,observables): inittime = int(time()) lasttime = 0 print "Processing...", sys.stdout.flush() if len(shape(observables)) == 0: array = zeros(snum,typecode='d') for i in arange(0,snum): array[i] = observables(i*stime) if i % 1024 == 0: lasttime = dotime(i,snum,inittime,lasttime) else: obslen = shape(observables)[0] array = zeros((snum,obslen),typecode='d') for i in arange(0,snum): for j in range(0,obslen): array[i,j] = observables[j](i*stime) if i % 1024 == 0: lasttime = dotime(i,snum,inittime,lasttime) currenttime = int(time()) - inittime print "\r...completed in %d s. " % currenttime return array |
array[i] = observables(i*stime) | array[i] = observables(zerotime+i*stime) | def getobsc(snum,stime,observables): inittime = int(time()) lasttime = 0 print "Processing...", sys.stdout.flush() if len(shape(observables)) == 0: array = zeros(snum,typecode='d') for i in arange(0,snum): array[i] = observables(i*stime) if i % 1024 == 0: lasttime = dotime(i,snum,inittime,lasttime) else: obslen = shape(observables)[0] array = zeros((snum,obslen),typecode='d') for i in arange(0,snum): for j in range(0,obslen): array[i,j] = observables[j](i*stime) if i % 1024 == 0: lasttime = dotime(i,snum,inittime,lasttime) currenttime = int(time()) - inittime print "\r...completed in %d s. " % currenttime return array |
array[i,j] = observables[j](i*stime) | array[i,j] = observables[j](zerotime+i*stime) | def getobsc(snum,stime,observables): inittime = int(time()) lasttime = 0 print "Processing...", sys.stdout.flush() if len(shape(observables)) == 0: array = zeros(snum,typecode='d') for i in arange(0,snum): array[i] = observables(i*stime) if i % 1024 == 0: lasttime = dotime(i,snum,inittime,lasttime) else: obslen = shape(observables)[0] array = zeros((snum,obslen),typecode='d') for i in arange(0,snum): for j in range(0,obslen): array[i,j] = observables[j](i*stime) if i % 1024 == 0: lasttime = dotime(i,snum,inittime,lasttime) currenttime = int(time()) - inittime print "\r...completed in %d s. " % currenttime return array |
for i in arange(0,snum): | for i in Numeric.arange(0,snum): | def getobs(snum,stime,observables,zerotime=0.0): if len(Numeric.shape(observables)) == 0: array = Numeric.zeros(snum,typecode='d') for i in arange(0,snum): array[i] = observables(zerotime+i*stime) else: obslen = Numeric.shape(observables)[0] array = Numeric.zeros((snum,obslen),typecode='d') for i in Numeric.arange(0,snum): for j in range(0,obslen): array[i,j] = observables[j](zerotime+i*stime) return array |
Ted's Julian date 2457023.5""" | Ted's Julian date 2457023.5.""" | def stdLISApositions(): """Returns four Numeric arrays corresponding to times [in seconds] along |
[t,p1,p2,p3] = stdlisapositions() | [t,p1,p2,p3] = stdLISApositions() | def stdSampledLISA(interp=1): |
assert os.system('python setup.py install --prefix=' + escapespace(thisdir)) == 0 | assert os.system('python setup.py install --prefix=' + escapespace(installdir)) == 0 | def findpackage(packagename,dirname): packagetargz = glob.glob(packagename + '-*.tar.gz') packagetgz = glob.glob(packagename + '-*.tgz') packagetar = glob.glob(packagename + '-*.tar') packagezip = glob.glob(packagename + '-*.zip') if packagetargz: print "Unpacking " + packagetargz[-1] os.system('tar zxvf ' + packagetargz[-1] + ' > /dev/null') elif packagetgz: print "Unpacking " + packagetgz[-1] os.system('tar zxvf ' + packagetgz[-1] + ' > /dev/null') elif packagetar: print "Unpacking " + packagetar[-1] os.system('tar xvf ' + packagetar[-1] + ' > /dev/null') elif packagezip: print "Unpacking " + packagezip[-1] os.system('unzip ' + packagezip[-1] + ' > /dev/null') dir = filter(os.path.isdir,glob.glob(dirname + '-*') + glob.glob(packagename + '-*')) print "Using unpacking dir " + dir[-1] return dir[-1] |
assert os.system('./configure --prefix=' + escapespace(thisdir)) == 0 | assert os.system('./configure --prefix=' + escapespace(installdir)) == 0 | def findpackage(packagename,dirname): packagetargz = glob.glob(packagename + '-*.tar.gz') packagetgz = glob.glob(packagename + '-*.tgz') packagetar = glob.glob(packagename + '-*.tar') packagezip = glob.glob(packagename + '-*.zip') if packagetargz: print "Unpacking " + packagetargz[-1] os.system('tar zxvf ' + packagetargz[-1] + ' > /dev/null') elif packagetgz: print "Unpacking " + packagetgz[-1] os.system('tar zxvf ' + packagetgz[-1] + ' > /dev/null') elif packagetar: print "Unpacking " + packagetar[-1] os.system('tar xvf ' + packagetar[-1] + ' > /dev/null') elif packagezip: print "Unpacking " + packagezip[-1] os.system('unzip ' + packagezip[-1] + ' > /dev/null') dir = filter(os.path.isdir,glob.glob(dirname + '-*') + glob.glob(packagename + '-*')) print "Using unpacking dir " + dir[-1] return dir[-1] |
assert os.system('python setup.py install --prefix=. --root=' + escapespace(thisdir)) == 0 | assert os.system('python setup.py install --prefix=. --root=' + escapespace(installdir)) == 0 | def findpackage(packagename,dirname): packagetargz = glob.glob(packagename + '-*.tar.gz') packagetgz = glob.glob(packagename + '-*.tgz') packagetar = glob.glob(packagename + '-*.tar') packagezip = glob.glob(packagename + '-*.zip') if packagetargz: print "Unpacking " + packagetargz[-1] os.system('tar zxvf ' + packagetargz[-1] + ' > /dev/null') elif packagetgz: print "Unpacking " + packagetgz[-1] os.system('tar zxvf ' + packagetgz[-1] + ' > /dev/null') elif packagetar: print "Unpacking " + packagetar[-1] os.system('tar xvf ' + packagetar[-1] + ' > /dev/null') elif packagezip: print "Unpacking " + packagezip[-1] os.system('unzip ' + packagezip[-1] + ' > /dev/null') dir = filter(os.path.isdir,glob.glob(dirname + '-*') + glob.glob(packagename + '-*')) print "Using unpacking dir " + dir[-1] return dir[-1] |
assert os.system('python setup.py install --prefix=' + escapespace(thisdir) + ' --with-numeric=' + escapespace(thisdir)) == 0 | assert os.system('python setup.py install --prefix=' + escapespace(installdir) + ' --with-numeric=' + escapespace(installdir)) == 0 | def findpackage(packagename,dirname): packagetargz = glob.glob(packagename + '-*.tar.gz') packagetgz = glob.glob(packagename + '-*.tgz') packagetar = glob.glob(packagename + '-*.tar') packagezip = glob.glob(packagename + '-*.zip') if packagetargz: print "Unpacking " + packagetargz[-1] os.system('tar zxvf ' + packagetargz[-1] + ' > /dev/null') elif packagetgz: print "Unpacking " + packagetgz[-1] os.system('tar zxvf ' + packagetgz[-1] + ' > /dev/null') elif packagetar: print "Unpacking " + packagetar[-1] os.system('tar xvf ' + packagetar[-1] + ' > /dev/null') elif packagezip: print "Unpacking " + packagezip[-1] os.system('unzip ' + packagezip[-1] + ' > /dev/null') dir = filter(os.path.isdir,glob.glob(dirname + '-*') + glob.glob(packagename + '-*')) print "Using unpacking dir " + dir[-1] return dir[-1] |
' --with-numpy=' + escapespace(thisdir) + ' --with-swig=' + escapespace(thisdir) + '/bin/swig --prefix=' + escapespace(thisdir))) == 0 | ' --with-numpy=' + escapespace(installdir) + ' --with-swig=' + escapespace(installdir) + '/bin/swig --prefix=' + escapespace(installdir))) == 0 | def findpackage(packagename,dirname): packagetargz = glob.glob(packagename + '-*.tar.gz') packagetgz = glob.glob(packagename + '-*.tgz') packagetar = glob.glob(packagename + '-*.tar') packagezip = glob.glob(packagename + '-*.zip') if packagetargz: print "Unpacking " + packagetargz[-1] os.system('tar zxvf ' + packagetargz[-1] + ' > /dev/null') elif packagetgz: print "Unpacking " + packagetgz[-1] os.system('tar zxvf ' + packagetgz[-1] + ' > /dev/null') elif packagetar: print "Unpacking " + packagetar[-1] os.system('tar xvf ' + packagetar[-1] + ' > /dev/null') elif packagezip: print "Unpacking " + packagezip[-1] os.system('unzip ' + packagezip[-1] + ' > /dev/null') dir = filter(os.path.isdir,glob.glob(dirname + '-*') + glob.glob(packagename + '-*')) print "Using unpacking dir " + dir[-1] return dir[-1] |
lambda x: ( str(2.0*math.pi - float(x)), 'Radian' ) ) | lambda x: ( float(x) != 0 and str(2.0*math.pi - float(x)) or '0', 'Radian' ) ) | def convertUnit(param,unitin,unitout,paramname=''): if unitout == unitin: return (param,unitin) if unitout == "Radian": if unitin == "Degree": return ((math.pi/180.0) * float(param),'Radian') elif unitin == "DMS": # space separated dms = map(float, param.split()) return ((math.pi/180.0) * (dms[0] + dms[1]/60.0 + dms[2]/3600.0),'Radian') elif unitin == "HMS": # space separated hms = map(float, param.split()) return ((15.0*math.pi/180.0) * (hms[0] + hms[1]/60.0 + hms[2]/3600.0),'Radian') if unitout == 'String': if paramname == 'SpectralType': if unitin == '1': if float(param) == 0.0: return ('WhiteFrequency','String') elif float(param) == 2.0: return ('WhitePhase','String') elif float(param) == -2.0: return ('WhiteAcceleration','String') if unitout == '1': if paramname == 'SpectralType': if unitin == 'String': if param == 'WhiteFrequency': return ('0.0','1') elif param == 'WhitePhase': return ('2.0','1') elif param == 'WhiteAcceleration': return ('-2.0','1') raise NotImplementedError, "convertUnit(): cannot convert %s from %s to %s (parameter %s)" % (param,unitin,unitout,paramname) |
lambda x: ( str(2.0*math.pi - float(x)), 'Radian' ) ) | lambda x: ( float(x) != 0 and str(2.0*math.pi - float(x)) or '0', 'Radian' ) ) conversionRules['Inclination'] = ( [('SLInclination','Radian')], lambda x: ( str(float(x) < math.pi and math.pi - float(x) or 3.0*math.pi - float(x)), 'Radian' ) ) conversionRules['SLInclination'] = ( [('Inclination','Radian')], lambda x: ( str(float(x) < math.pi and math.pi - float(x) or 3.0*math.pi - float(x)), 'Radian' ) ) | def convertUnit(param,unitin,unitout,paramname=''): if unitout == unitin: return (param,unitin) if unitout == "Radian": if unitin == "Degree": return ((math.pi/180.0) * float(param),'Radian') elif unitin == "DMS": # space separated dms = map(float, param.split()) return ((math.pi/180.0) * (dms[0] + dms[1]/60.0 + dms[2]/3600.0),'Radian') elif unitin == "HMS": # space separated hms = map(float, param.split()) return ((15.0*math.pi/180.0) * (hms[0] + hms[1]/60.0 + hms[2]/3600.0),'Radian') if unitout == 'String': if paramname == 'SpectralType': if unitin == '1': if float(param) == 0.0: return ('WhiteFrequency','String') elif float(param) == 2.0: return ('WhitePhase','String') elif float(param) == -2.0: return ('WhiteAcceleration','String') if unitout == '1': if paramname == 'SpectralType': if unitin == 'String': if param == 'WhiteFrequency': return ('0.0','1') elif param == 'WhitePhase': return ('2.0','1') elif param == 'WhiteAcceleration': return ('-2.0','1') raise NotImplementedError, "convertUnit(): cannot convert %s from %s to %s (parameter %s)" % (param,unitin,unitout,paramname) |
conversionRules['InitialPosition'] = ( [('InitialEta','Radian'),('InitialXi','Radian'),('Armswitch','1')], | conversionRules['InitialPosition'] = ( [('InitialEta','Radian'),('InitialXi','Radian'),('ArmSwitch','1')], | def ex2ipr(e,x,s): eta = float(e) xi = float(x) sw = float(s) if sw > 0: raise NotImplementedError, "convertParameters(): LISA eta/xi configuration with sw > 0 not compatible with PseudoLISA" initpos = eta initrot = xi + initpos - 1.5*math.pi return ( (str(initpos),'Radian'), (str(initrot),'Radian') ) |
conversionRules['InitialRotation'] = ( [('InitialEta','Radian'),('InitialXi','Radian'),('Armswitch','1')], | conversionRules['InitialRotation'] = ( [('InitialEta','Radian'),('InitialXi','Radian'),('ArmSwitch','1')], | def ex2ipr(e,x,s): eta = float(e) xi = float(x) sw = float(s) if sw > 0: raise NotImplementedError, "convertParameters(): LISA eta/xi configuration with sw > 0 not compatible with PseudoLISA" initpos = eta initrot = xi + initpos - 1.5*math.pi return ( (str(initpos),'Radian'), (str(initrot),'Radian') ) |
XMLToObject['EMRI'] = ('EMRI',lisawp_emri.EMRI) | XMLToObject['ExtremeMassRatioInspiral'] = ('EMRI',lisawp_emri.EMRI) | def makeoptional(parlist): return map(lambda p: lambda s: p[0] in s or p,parlist) |
self.coupletag('Param',{'Name': 'TimeOffset','Type': 's'}, | self.coupletag('Param',{'Name': 'TimeOffset','Type': 'Second'}, | def writeTimeSeries(self,TimeSeries): # write out the TimeSeries defined in TimeSeries self.opentag('XSIL',{'Type': 'TimeSeries', 'Name': TimeSeries.description}) |
self.coupletag('Param',{'Name': 'Cadence','Unit': 's'}, | self.coupletag('Param',{'Name': 'Cadence','Unit': 'Second'}, | def writeTimeSeries(self,TimeSeries): # write out the TimeSeries defined in TimeSeries self.opentag('XSIL',{'Type': 'TimeSeries', 'Name': TimeSeries.description}) |
self.coupletag('Param',{'Name': 'Duration','Unit': 's'}, | self.coupletag('Param',{'Name': 'Duration','Unit': 'Second'}, | def writeTimeSeries(self,TimeSeries): # write out the TimeSeries defined in TimeSeries self.opentag('XSIL',{'Type': 'TimeSeries', 'Name': TimeSeries.description}) |
tree = p(f.read()) | lines = f.read() | def __init__(self,filename): p = pyRXP.Parser() |
import numpy.dft as FFT | import numpy.fft as FFT | def sn(signal,noise,stime,npatches): """Compute the optimal S/N for signal, sampled at intervals of stime, and for the total duration represented in the array, against noise represented by the time series noise; npatches overlapping periods are used to estimate the PSD of the noise.""" # compute signal spectrum without windowing or averaging sspec = spect(signal,stime,0) # compute the noise spectrum, using segment averaging nspec = spect(noise,stime,npatches) # interpolate the noise to be defined on the same frequencies # of the signal's spectrum ispec = Numeric.zeros(Numeric.shape(sspec),dtype='d') ispec[:,0] = sspec[:,0] # ispec[:,1] = arrayfns.interp(nspec[:,1],nspec[:,0],ispec[:,0]) ispec[:,1] = linearinterpolate(nspec[:,1],nspec[:,0],ispec[:,0]) # the (S/N)^2 is given by 2T times the integrated ratio # of the spectral densities (the factor of 2 because the spectral # density is one-sided); notice however that the df is 1/T, # so we need only to sum up the array containing the ratio, # and multiply by two sratio = Numeric.zeros(Numeric.shape(sspec)[0],dtype='d') sratio[1:] = sspec[1:,1] / ispec[1:,1] sn2 = 2.0 * sum(sratio[1:]) return math.sqrt(sn2) |
""" % (pythonpath, pythonpath) | SYNTHLISABASE="%s"; export SYNTHLISABASE """ % (pythonpath, pythonpath, installpath) | def runswig(source,cppfile,pyfile,deps): if not os.path.isfile(cppfile) or not os.path.isfile(pyfile) \ or newer_group(deps,cppfile) or newer_group(deps,pyfile): try: spawn([swig_bin,'-w402','-c++','-python','-o',cppfile,source]) except: print 'Sorry, I am unable to swig the modified ' + lisasim_isource sys.exit(cmd) |
""" % (pythonpath, pythonpath) | setenv SYNTHLISABASE %s """ % (pythonpath, pythonpath, installpath) | def runswig(source,cppfile,pyfile,deps): if not os.path.isfile(cppfile) or not os.path.isfile(pyfile) \ or newer_group(deps,cppfile) or newer_group(deps,pyfile): try: spawn([swig_bin,'-w402','-c++','-python','-o',cppfile,source]) except: print 'Sorry, I am unable to swig the modified ' + lisasim_isource sys.exit(cmd) |
version = '1.2.4', | version = '1.2.6', | def runswig(source,cppfile,pyfile,deps): if not os.path.isfile(cppfile) or not os.path.isfile(pyfile) \ or newer_group(deps,cppfile) or newer_group(deps,pyfile): try: spawn([swig_bin,'-w402','-c++','-python','-o',cppfile,source]) except: print 'Sorry, I am unable to swig the modified ' + lisasim_isource sys.exit(cmd) |
db = CountryByIP(db_file) | try: db = CountryByIP(db_file) except IOError, exc: import errno if exc.errno==errno.ENOENT: sys.exit('Database not found. Run update.py to create it.') else: sys.exit('Cannot open database: %s' % exc) | def __getitem__(self, ip): offset = 0 fp = self.fp for part in ip.split('.'): start = offset+int(part)*4 fp.seek(start) value = fp.read(4) assert len(value)==4 if value[:2]=='\xFF\xFF': if value[2:]=='\x00\x00': raise KeyError(ip) else: return value[2:] offset = struct.unpack('!I', value)[0] raise RuntimeError('ip2cc database is briken') # must never reach here |
try: ln = pobj.stdout.readline() except IOError: | ln = pobj.stdout.readline() if alarm_triggered: | def run_tlsmd(webtlsmdd, jdict): job_id = jdict["job_id"] tlsmd = jdict["tlsmd"] ## write the tlsmd execution command out to a file open("tlsmdcmd.txt", "w").write(" ".join(tlsmd) + '\n') pobj = subprocess.Popen(tlsmd, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, close_fds = True, bufsize = 0) logfil = open("log.txt", "w") chain_time_dict = {} time_chain_id = None time_begin = None signal.signal(signal.SIGALRM, sigalrm_handler) while True: signal.alarm(TIMEOUT_SECS) try: ln = pobj.stdout.readline() except IOError: os.kill(pobj.pid, signal.SIGTERM) break if len(ln) == 0: break signal.alarm(0) logfil.write(ln) logfil.flush() pobj.wait() logfil.close() |
if self.struct.title: | if self.struct.header: | def html_globals(self): """Output a HTML table displaying global TLSMD settings. """ if conf.globalconf.tls_model in ["ISOT", "NLISOT"]: tls_model = "Isotropic" elif conf.globalconf.tls_model in ["ANISO", "NLANISO"]: tls_model = "Anisotropic" |
if numpy.allclose(L1, 0.0) or type(L1)==complex: | if numpy.allclose(L1, 0.0) or type(L1)==numpy.complex_: | def calc_itls_center_of_reaction(iT, iL, iS, origin): """iT is a single float; iL[3,3]; iS[3] """ ## construct TLS tensors from isotropic TLS description T0 = numpy.array([[iT, 0.0, 0.0], [0.0, iT, 0.0], [0.0, 0.0, iT]], float) L0 = iL.copy() S0 = numpy.array([ [ 0.0, 0.0, iS[1]], [iS[0], 0.0, 0.0], [ 0.0, iS[2], 0.0] ], float) ## LSMALL is the smallest magnitude of L before it is considered 0.0 LSMALL = 0.5 * Constants.DEG2RAD2 rdict = {} rdict["T'"] = T0.copy() rdict["L'"] = L0.copy() rdict["S'"] = S0.copy() rdict["rT'"] = T0.copy() rdict["L1_eigen_val"] = 0.0 rdict["L2_eigen_val"] = 0.0 rdict["L3_eigen_val"] = 0.0 rdict["L1_rmsd"] = 0.0 rdict["L2_rmsd"] = 0.0 rdict["L3_rmsd"] = 0.0 rdict["L1_eigen_vec"] = numpy.zeros(3, float) rdict["L2_eigen_vec"] = numpy.zeros(3, float) rdict["L3_eigen_vec"] = numpy.zeros(3, float) rdict["RHO"] = numpy.zeros(3, float) rdict["COR"] = origin rdict["L1_rho"] = numpy.zeros(3, float) rdict["L2_rho"] = numpy.zeros(3, float) rdict["L3_rho"] = numpy.zeros(3, float) rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 rdict["Tr1_eigen_val"] = 0.0 rdict["Tr2_eigen_val"] = 0.0 rdict["Tr3_eigen_val"] = 0.0 rdict["Tr1_rmsd"] = 0.0 rdict["Tr2_rmsd"] = 0.0 rdict["Tr3_rmsd"] = 0.0 ## set the L tensor eigenvalues and eigenvectors (L_evals, RL) = numpy.linalg.eigenvectors(L0) L1, L2, L3 = L_evals good_L_eigens = [] if numpy.allclose(L1, 0.0) or type(L1)==complex: L1 = 0.0 else: good_L_eigens.append(0) if numpy.allclose(L2, 0.0) or type(L2)==complex: L2 = 0.0 else: good_L_eigens.append(1) if numpy.allclose(L3, 0.0) or type(L3)==complex: L3 = 0.0 else: good_L_eigens.append(2) ## no good L eigen values if len(good_L_eigens)==0: Tr1, Tr2, Tr3 = numpy.linalg.eigenvalues(T0) if numpy.allclose(Tr1, 0.0) or type(Tr1)==complex: Tr1 = 0.0 if numpy.allclose(Tr2, 0.0) or type(Tr2)==complex: Tr2 = 0.0 if numpy.allclose(Tr3, 0.0) or type(Tr3)==complex: Tr3 = 0.0 rdict["Tr1_eigen_val"] = Tr1 rdict["Tr2_eigen_val"] = Tr2 rdict["Tr3_eigen_val"] = Tr3 rdict["Tr1_rmsd"] = calc_rmsd(Tr1) rdict["Tr2_rmsd"] = calc_rmsd(Tr2) rdict["Tr3_rmsd"] = calc_rmsd(Tr3) return rdict ## one good eigen value -- reconstruct RL about it elif len(good_L_eigens)==1: i = good_L_eigens[0] evec = RL[i] RZt = numpy.transpose(AtomMath.rmatrixz(evec)) xevec = numpy.matrixmultiply(RZt, numpy.array([1.0, 0.0, 0.0], float)) yevec = numpy.matrixmultiply(RZt, numpy.array([0.0, 1.0, 0.0], float)) if i==0: RL[1] = xevec RL[2] = yevec elif i==1: RL[0] = xevec RL[2] = yevec elif i==2: RL[0] = xevec RL[1] = yevec ## two good eigen values -- reconstruct RL about them elif len(good_L_eigens)==2: i = good_L_eigens[0] j = good_L_eigens[1] xevec = AtomMath.normalize(numpy.cross(RL[i], RL[j])) for k in range(3): if k==i: continue if k==j: continue RL[k] = xevec break rdict["L1_eigen_val"] = L1 rdict["L2_eigen_val"] = L2 rdict["L3_eigen_val"] = L3 rdict["L1_rmsd"] = calc_rmsd(L1) rdict["L2_rmsd"] = calc_rmsd(L2) rdict["L3_rmsd"] = calc_rmsd(L3) rdict["L1_eigen_vec"] = RL[0].copy() rdict["L2_eigen_vec"] = RL[1].copy() rdict["L3_eigen_vec"] = RL[2].copy() ## begin tensor transformations which depend upon ## the eigenvectors of L0 being well-determined ## make sure RLt is right-handed if numpy.allclose(numpy.linalg.determinant(RL), -1.0): I = numpy.identity(3, float) I[0,0] = -1.0 RL = numpy.matrixmultiply(I, RL) if not numpy.allclose(numpy.linalg.determinant(RL), 1.0): return rdict RLt = numpy.transpose(RL) ## carrot-L tensor (tensor WRT principal axes of L) cL = numpy.matrixmultiply(numpy.matrixmultiply(RL, L0), RLt) ## carrot-T tensor (T tensor WRT principal axes of L) cT = numpy.matrixmultiply(numpy.matrixmultiply(RL, T0), RLt) ## carrot-S tensor (S tensor WRT principal axes of L) cS = numpy.matrixmultiply(numpy.matrixmultiply(RL, S0), RLt) ## ^rho: the origin-shift vector in the coordinate system of L L23 = L2 + L3 L13 = L1 + L3 L12 = L1 + L2 ## shift for L1 if not numpy.allclose(L1, 0.0) and abs(L23)>LSMALL: crho1 = (cS[1,2] - cS[2,1]) / L23 else: crho1 = 0.0 if not numpy.allclose(L2, 0.0) and abs(L13)>LSMALL: crho2 = (cS[2,0] - cS[0,2]) / L13 else: crho2 = 0.0 if not numpy.allclose(L3, 0.0) and abs(L12)>LSMALL: crho3 = (cS[0,1] - cS[1,0]) / L12 else: crho3 = 0.0 crho = numpy.array([crho1, crho2, crho3], float) ## rho: the origin-shift vector in orthogonal coordinates rho = numpy.matrixmultiply(RLt, crho) rdict["RHO"] = rho rdict["COR"] = origin + rho ## set up the origin shift matrix PRHO WRT orthogonal axes PRHO = numpy.array([ [ 0.0, rho[2], -rho[1]], [-rho[2], 0.0, rho[0]], [ rho[1], -rho[0], 0.0] ], float) ## set up the origin shift matrix cPRHO WRT libration axes cPRHO = numpy.array([ [ 0.0, crho[2], -crho[1]], [-crho[2], 0.0, crho[0]], [ crho[1], -crho[0], 0.0] ], float) ## calculate tranpose of cPRHO, ans cS cSt = numpy.transpose(cS) cPRHOt = numpy.transpose(cPRHO) ## calculate S'^ = S^ + L^*pRHOt cSp = cS + numpy.matrixmultiply(cL, cPRHOt) ## calculate T'^ = cT + cPRHO*S^ + cSt*cPRHOt + cPRHO*cL*cPRHOt * cTp = cT + numpy.matrixmultiply(cPRHO, cS) + numpy.matrixmultiply(cSt, cPRHOt) + \ numpy.matrixmultiply(numpy.matrixmultiply(cPRHO, cL), cPRHOt) ## transpose of PRHO and S PRHOt = numpy.transpose(PRHO) St = numpy.transpose(S0) ## calculate S' = S + L*PRHOt Sp = S0 + numpy.matrixmultiply(L0, PRHOt) rdict["S'"] = Sp ## calculate T' = T + PRHO*S + St*PRHOT + PRHO*L*PRHOt Tp = T0 + numpy.matrixmultiply(PRHO, S0) + numpy.matrixmultiply(St, PRHOt) + \ numpy.matrixmultiply(numpy.matrixmultiply(PRHO, L0), PRHOt) rdict["T'"] = Tp ## now calculate the TLS motion description using 3 non ## intersecting screw axes, with one ## libration axis 1 shift in the L coordinate system ## you cannot determine axis shifts from the isotropic TLS parameters cL1rho = numpy.zeros(3, float) cL2rho = numpy.zeros(3, float) cL3rho = numpy.zeros(3, float) ## libration axes shifts in the origional orthogonal ## coordinate system rdict["L1_rho"] = numpy.matrixmultiply(RLt, cL1rho) rdict["L2_rho"] = numpy.matrixmultiply(RLt, cL2rho) rdict["L3_rho"] = numpy.matrixmultiply(RLt, cL3rho) ## calculate screw pitches (A*R / R*R) = (A/R) ## no screw pitches either rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 ## rotate the newly calculated reduced-T tensor from the carrot ## coordinate system (coordinate system of L) back to the structure ## coordinate system Tiso = numpy.trace(Tp) / 3.0 rdict["rT'"] = Tiso * numpy.identity(3, float) rdict["Tr1_eigen_val"] = Tiso rdict["Tr2_eigen_val"] = Tiso rdict["Tr3_eigen_val"] = Tiso rdict["Tr1_rmsd"] = calc_rmsd(Tiso) rdict["Tr2_rmsd"] = calc_rmsd(Tiso) rdict["Tr3_rmsd"] = calc_rmsd(Tiso) return rdict |
if numpy.allclose(L2, 0.0) or type(L2)==complex: | if numpy.allclose(L2, 0.0) or type(L2)==numpy.complex_: | def calc_itls_center_of_reaction(iT, iL, iS, origin): """iT is a single float; iL[3,3]; iS[3] """ ## construct TLS tensors from isotropic TLS description T0 = numpy.array([[iT, 0.0, 0.0], [0.0, iT, 0.0], [0.0, 0.0, iT]], float) L0 = iL.copy() S0 = numpy.array([ [ 0.0, 0.0, iS[1]], [iS[0], 0.0, 0.0], [ 0.0, iS[2], 0.0] ], float) ## LSMALL is the smallest magnitude of L before it is considered 0.0 LSMALL = 0.5 * Constants.DEG2RAD2 rdict = {} rdict["T'"] = T0.copy() rdict["L'"] = L0.copy() rdict["S'"] = S0.copy() rdict["rT'"] = T0.copy() rdict["L1_eigen_val"] = 0.0 rdict["L2_eigen_val"] = 0.0 rdict["L3_eigen_val"] = 0.0 rdict["L1_rmsd"] = 0.0 rdict["L2_rmsd"] = 0.0 rdict["L3_rmsd"] = 0.0 rdict["L1_eigen_vec"] = numpy.zeros(3, float) rdict["L2_eigen_vec"] = numpy.zeros(3, float) rdict["L3_eigen_vec"] = numpy.zeros(3, float) rdict["RHO"] = numpy.zeros(3, float) rdict["COR"] = origin rdict["L1_rho"] = numpy.zeros(3, float) rdict["L2_rho"] = numpy.zeros(3, float) rdict["L3_rho"] = numpy.zeros(3, float) rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 rdict["Tr1_eigen_val"] = 0.0 rdict["Tr2_eigen_val"] = 0.0 rdict["Tr3_eigen_val"] = 0.0 rdict["Tr1_rmsd"] = 0.0 rdict["Tr2_rmsd"] = 0.0 rdict["Tr3_rmsd"] = 0.0 ## set the L tensor eigenvalues and eigenvectors (L_evals, RL) = numpy.linalg.eigenvectors(L0) L1, L2, L3 = L_evals good_L_eigens = [] if numpy.allclose(L1, 0.0) or type(L1)==complex: L1 = 0.0 else: good_L_eigens.append(0) if numpy.allclose(L2, 0.0) or type(L2)==complex: L2 = 0.0 else: good_L_eigens.append(1) if numpy.allclose(L3, 0.0) or type(L3)==complex: L3 = 0.0 else: good_L_eigens.append(2) ## no good L eigen values if len(good_L_eigens)==0: Tr1, Tr2, Tr3 = numpy.linalg.eigenvalues(T0) if numpy.allclose(Tr1, 0.0) or type(Tr1)==complex: Tr1 = 0.0 if numpy.allclose(Tr2, 0.0) or type(Tr2)==complex: Tr2 = 0.0 if numpy.allclose(Tr3, 0.0) or type(Tr3)==complex: Tr3 = 0.0 rdict["Tr1_eigen_val"] = Tr1 rdict["Tr2_eigen_val"] = Tr2 rdict["Tr3_eigen_val"] = Tr3 rdict["Tr1_rmsd"] = calc_rmsd(Tr1) rdict["Tr2_rmsd"] = calc_rmsd(Tr2) rdict["Tr3_rmsd"] = calc_rmsd(Tr3) return rdict ## one good eigen value -- reconstruct RL about it elif len(good_L_eigens)==1: i = good_L_eigens[0] evec = RL[i] RZt = numpy.transpose(AtomMath.rmatrixz(evec)) xevec = numpy.matrixmultiply(RZt, numpy.array([1.0, 0.0, 0.0], float)) yevec = numpy.matrixmultiply(RZt, numpy.array([0.0, 1.0, 0.0], float)) if i==0: RL[1] = xevec RL[2] = yevec elif i==1: RL[0] = xevec RL[2] = yevec elif i==2: RL[0] = xevec RL[1] = yevec ## two good eigen values -- reconstruct RL about them elif len(good_L_eigens)==2: i = good_L_eigens[0] j = good_L_eigens[1] xevec = AtomMath.normalize(numpy.cross(RL[i], RL[j])) for k in range(3): if k==i: continue if k==j: continue RL[k] = xevec break rdict["L1_eigen_val"] = L1 rdict["L2_eigen_val"] = L2 rdict["L3_eigen_val"] = L3 rdict["L1_rmsd"] = calc_rmsd(L1) rdict["L2_rmsd"] = calc_rmsd(L2) rdict["L3_rmsd"] = calc_rmsd(L3) rdict["L1_eigen_vec"] = RL[0].copy() rdict["L2_eigen_vec"] = RL[1].copy() rdict["L3_eigen_vec"] = RL[2].copy() ## begin tensor transformations which depend upon ## the eigenvectors of L0 being well-determined ## make sure RLt is right-handed if numpy.allclose(numpy.linalg.determinant(RL), -1.0): I = numpy.identity(3, float) I[0,0] = -1.0 RL = numpy.matrixmultiply(I, RL) if not numpy.allclose(numpy.linalg.determinant(RL), 1.0): return rdict RLt = numpy.transpose(RL) ## carrot-L tensor (tensor WRT principal axes of L) cL = numpy.matrixmultiply(numpy.matrixmultiply(RL, L0), RLt) ## carrot-T tensor (T tensor WRT principal axes of L) cT = numpy.matrixmultiply(numpy.matrixmultiply(RL, T0), RLt) ## carrot-S tensor (S tensor WRT principal axes of L) cS = numpy.matrixmultiply(numpy.matrixmultiply(RL, S0), RLt) ## ^rho: the origin-shift vector in the coordinate system of L L23 = L2 + L3 L13 = L1 + L3 L12 = L1 + L2 ## shift for L1 if not numpy.allclose(L1, 0.0) and abs(L23)>LSMALL: crho1 = (cS[1,2] - cS[2,1]) / L23 else: crho1 = 0.0 if not numpy.allclose(L2, 0.0) and abs(L13)>LSMALL: crho2 = (cS[2,0] - cS[0,2]) / L13 else: crho2 = 0.0 if not numpy.allclose(L3, 0.0) and abs(L12)>LSMALL: crho3 = (cS[0,1] - cS[1,0]) / L12 else: crho3 = 0.0 crho = numpy.array([crho1, crho2, crho3], float) ## rho: the origin-shift vector in orthogonal coordinates rho = numpy.matrixmultiply(RLt, crho) rdict["RHO"] = rho rdict["COR"] = origin + rho ## set up the origin shift matrix PRHO WRT orthogonal axes PRHO = numpy.array([ [ 0.0, rho[2], -rho[1]], [-rho[2], 0.0, rho[0]], [ rho[1], -rho[0], 0.0] ], float) ## set up the origin shift matrix cPRHO WRT libration axes cPRHO = numpy.array([ [ 0.0, crho[2], -crho[1]], [-crho[2], 0.0, crho[0]], [ crho[1], -crho[0], 0.0] ], float) ## calculate tranpose of cPRHO, ans cS cSt = numpy.transpose(cS) cPRHOt = numpy.transpose(cPRHO) ## calculate S'^ = S^ + L^*pRHOt cSp = cS + numpy.matrixmultiply(cL, cPRHOt) ## calculate T'^ = cT + cPRHO*S^ + cSt*cPRHOt + cPRHO*cL*cPRHOt * cTp = cT + numpy.matrixmultiply(cPRHO, cS) + numpy.matrixmultiply(cSt, cPRHOt) + \ numpy.matrixmultiply(numpy.matrixmultiply(cPRHO, cL), cPRHOt) ## transpose of PRHO and S PRHOt = numpy.transpose(PRHO) St = numpy.transpose(S0) ## calculate S' = S + L*PRHOt Sp = S0 + numpy.matrixmultiply(L0, PRHOt) rdict["S'"] = Sp ## calculate T' = T + PRHO*S + St*PRHOT + PRHO*L*PRHOt Tp = T0 + numpy.matrixmultiply(PRHO, S0) + numpy.matrixmultiply(St, PRHOt) + \ numpy.matrixmultiply(numpy.matrixmultiply(PRHO, L0), PRHOt) rdict["T'"] = Tp ## now calculate the TLS motion description using 3 non ## intersecting screw axes, with one ## libration axis 1 shift in the L coordinate system ## you cannot determine axis shifts from the isotropic TLS parameters cL1rho = numpy.zeros(3, float) cL2rho = numpy.zeros(3, float) cL3rho = numpy.zeros(3, float) ## libration axes shifts in the origional orthogonal ## coordinate system rdict["L1_rho"] = numpy.matrixmultiply(RLt, cL1rho) rdict["L2_rho"] = numpy.matrixmultiply(RLt, cL2rho) rdict["L3_rho"] = numpy.matrixmultiply(RLt, cL3rho) ## calculate screw pitches (A*R / R*R) = (A/R) ## no screw pitches either rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 ## rotate the newly calculated reduced-T tensor from the carrot ## coordinate system (coordinate system of L) back to the structure ## coordinate system Tiso = numpy.trace(Tp) / 3.0 rdict["rT'"] = Tiso * numpy.identity(3, float) rdict["Tr1_eigen_val"] = Tiso rdict["Tr2_eigen_val"] = Tiso rdict["Tr3_eigen_val"] = Tiso rdict["Tr1_rmsd"] = calc_rmsd(Tiso) rdict["Tr2_rmsd"] = calc_rmsd(Tiso) rdict["Tr3_rmsd"] = calc_rmsd(Tiso) return rdict |
if numpy.allclose(L3, 0.0) or type(L3)==complex: | if numpy.allclose(L3, 0.0) or type(L3)==numpy.complex_: | def calc_itls_center_of_reaction(iT, iL, iS, origin): """iT is a single float; iL[3,3]; iS[3] """ ## construct TLS tensors from isotropic TLS description T0 = numpy.array([[iT, 0.0, 0.0], [0.0, iT, 0.0], [0.0, 0.0, iT]], float) L0 = iL.copy() S0 = numpy.array([ [ 0.0, 0.0, iS[1]], [iS[0], 0.0, 0.0], [ 0.0, iS[2], 0.0] ], float) ## LSMALL is the smallest magnitude of L before it is considered 0.0 LSMALL = 0.5 * Constants.DEG2RAD2 rdict = {} rdict["T'"] = T0.copy() rdict["L'"] = L0.copy() rdict["S'"] = S0.copy() rdict["rT'"] = T0.copy() rdict["L1_eigen_val"] = 0.0 rdict["L2_eigen_val"] = 0.0 rdict["L3_eigen_val"] = 0.0 rdict["L1_rmsd"] = 0.0 rdict["L2_rmsd"] = 0.0 rdict["L3_rmsd"] = 0.0 rdict["L1_eigen_vec"] = numpy.zeros(3, float) rdict["L2_eigen_vec"] = numpy.zeros(3, float) rdict["L3_eigen_vec"] = numpy.zeros(3, float) rdict["RHO"] = numpy.zeros(3, float) rdict["COR"] = origin rdict["L1_rho"] = numpy.zeros(3, float) rdict["L2_rho"] = numpy.zeros(3, float) rdict["L3_rho"] = numpy.zeros(3, float) rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 rdict["Tr1_eigen_val"] = 0.0 rdict["Tr2_eigen_val"] = 0.0 rdict["Tr3_eigen_val"] = 0.0 rdict["Tr1_rmsd"] = 0.0 rdict["Tr2_rmsd"] = 0.0 rdict["Tr3_rmsd"] = 0.0 ## set the L tensor eigenvalues and eigenvectors (L_evals, RL) = numpy.linalg.eigenvectors(L0) L1, L2, L3 = L_evals good_L_eigens = [] if numpy.allclose(L1, 0.0) or type(L1)==complex: L1 = 0.0 else: good_L_eigens.append(0) if numpy.allclose(L2, 0.0) or type(L2)==complex: L2 = 0.0 else: good_L_eigens.append(1) if numpy.allclose(L3, 0.0) or type(L3)==complex: L3 = 0.0 else: good_L_eigens.append(2) ## no good L eigen values if len(good_L_eigens)==0: Tr1, Tr2, Tr3 = numpy.linalg.eigenvalues(T0) if numpy.allclose(Tr1, 0.0) or type(Tr1)==complex: Tr1 = 0.0 if numpy.allclose(Tr2, 0.0) or type(Tr2)==complex: Tr2 = 0.0 if numpy.allclose(Tr3, 0.0) or type(Tr3)==complex: Tr3 = 0.0 rdict["Tr1_eigen_val"] = Tr1 rdict["Tr2_eigen_val"] = Tr2 rdict["Tr3_eigen_val"] = Tr3 rdict["Tr1_rmsd"] = calc_rmsd(Tr1) rdict["Tr2_rmsd"] = calc_rmsd(Tr2) rdict["Tr3_rmsd"] = calc_rmsd(Tr3) return rdict ## one good eigen value -- reconstruct RL about it elif len(good_L_eigens)==1: i = good_L_eigens[0] evec = RL[i] RZt = numpy.transpose(AtomMath.rmatrixz(evec)) xevec = numpy.matrixmultiply(RZt, numpy.array([1.0, 0.0, 0.0], float)) yevec = numpy.matrixmultiply(RZt, numpy.array([0.0, 1.0, 0.0], float)) if i==0: RL[1] = xevec RL[2] = yevec elif i==1: RL[0] = xevec RL[2] = yevec elif i==2: RL[0] = xevec RL[1] = yevec ## two good eigen values -- reconstruct RL about them elif len(good_L_eigens)==2: i = good_L_eigens[0] j = good_L_eigens[1] xevec = AtomMath.normalize(numpy.cross(RL[i], RL[j])) for k in range(3): if k==i: continue if k==j: continue RL[k] = xevec break rdict["L1_eigen_val"] = L1 rdict["L2_eigen_val"] = L2 rdict["L3_eigen_val"] = L3 rdict["L1_rmsd"] = calc_rmsd(L1) rdict["L2_rmsd"] = calc_rmsd(L2) rdict["L3_rmsd"] = calc_rmsd(L3) rdict["L1_eigen_vec"] = RL[0].copy() rdict["L2_eigen_vec"] = RL[1].copy() rdict["L3_eigen_vec"] = RL[2].copy() ## begin tensor transformations which depend upon ## the eigenvectors of L0 being well-determined ## make sure RLt is right-handed if numpy.allclose(numpy.linalg.determinant(RL), -1.0): I = numpy.identity(3, float) I[0,0] = -1.0 RL = numpy.matrixmultiply(I, RL) if not numpy.allclose(numpy.linalg.determinant(RL), 1.0): return rdict RLt = numpy.transpose(RL) ## carrot-L tensor (tensor WRT principal axes of L) cL = numpy.matrixmultiply(numpy.matrixmultiply(RL, L0), RLt) ## carrot-T tensor (T tensor WRT principal axes of L) cT = numpy.matrixmultiply(numpy.matrixmultiply(RL, T0), RLt) ## carrot-S tensor (S tensor WRT principal axes of L) cS = numpy.matrixmultiply(numpy.matrixmultiply(RL, S0), RLt) ## ^rho: the origin-shift vector in the coordinate system of L L23 = L2 + L3 L13 = L1 + L3 L12 = L1 + L2 ## shift for L1 if not numpy.allclose(L1, 0.0) and abs(L23)>LSMALL: crho1 = (cS[1,2] - cS[2,1]) / L23 else: crho1 = 0.0 if not numpy.allclose(L2, 0.0) and abs(L13)>LSMALL: crho2 = (cS[2,0] - cS[0,2]) / L13 else: crho2 = 0.0 if not numpy.allclose(L3, 0.0) and abs(L12)>LSMALL: crho3 = (cS[0,1] - cS[1,0]) / L12 else: crho3 = 0.0 crho = numpy.array([crho1, crho2, crho3], float) ## rho: the origin-shift vector in orthogonal coordinates rho = numpy.matrixmultiply(RLt, crho) rdict["RHO"] = rho rdict["COR"] = origin + rho ## set up the origin shift matrix PRHO WRT orthogonal axes PRHO = numpy.array([ [ 0.0, rho[2], -rho[1]], [-rho[2], 0.0, rho[0]], [ rho[1], -rho[0], 0.0] ], float) ## set up the origin shift matrix cPRHO WRT libration axes cPRHO = numpy.array([ [ 0.0, crho[2], -crho[1]], [-crho[2], 0.0, crho[0]], [ crho[1], -crho[0], 0.0] ], float) ## calculate tranpose of cPRHO, ans cS cSt = numpy.transpose(cS) cPRHOt = numpy.transpose(cPRHO) ## calculate S'^ = S^ + L^*pRHOt cSp = cS + numpy.matrixmultiply(cL, cPRHOt) ## calculate T'^ = cT + cPRHO*S^ + cSt*cPRHOt + cPRHO*cL*cPRHOt * cTp = cT + numpy.matrixmultiply(cPRHO, cS) + numpy.matrixmultiply(cSt, cPRHOt) + \ numpy.matrixmultiply(numpy.matrixmultiply(cPRHO, cL), cPRHOt) ## transpose of PRHO and S PRHOt = numpy.transpose(PRHO) St = numpy.transpose(S0) ## calculate S' = S + L*PRHOt Sp = S0 + numpy.matrixmultiply(L0, PRHOt) rdict["S'"] = Sp ## calculate T' = T + PRHO*S + St*PRHOT + PRHO*L*PRHOt Tp = T0 + numpy.matrixmultiply(PRHO, S0) + numpy.matrixmultiply(St, PRHOt) + \ numpy.matrixmultiply(numpy.matrixmultiply(PRHO, L0), PRHOt) rdict["T'"] = Tp ## now calculate the TLS motion description using 3 non ## intersecting screw axes, with one ## libration axis 1 shift in the L coordinate system ## you cannot determine axis shifts from the isotropic TLS parameters cL1rho = numpy.zeros(3, float) cL2rho = numpy.zeros(3, float) cL3rho = numpy.zeros(3, float) ## libration axes shifts in the origional orthogonal ## coordinate system rdict["L1_rho"] = numpy.matrixmultiply(RLt, cL1rho) rdict["L2_rho"] = numpy.matrixmultiply(RLt, cL2rho) rdict["L3_rho"] = numpy.matrixmultiply(RLt, cL3rho) ## calculate screw pitches (A*R / R*R) = (A/R) ## no screw pitches either rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 ## rotate the newly calculated reduced-T tensor from the carrot ## coordinate system (coordinate system of L) back to the structure ## coordinate system Tiso = numpy.trace(Tp) / 3.0 rdict["rT'"] = Tiso * numpy.identity(3, float) rdict["Tr1_eigen_val"] = Tiso rdict["Tr2_eigen_val"] = Tiso rdict["Tr3_eigen_val"] = Tiso rdict["Tr1_rmsd"] = calc_rmsd(Tiso) rdict["Tr2_rmsd"] = calc_rmsd(Tiso) rdict["Tr3_rmsd"] = calc_rmsd(Tiso) return rdict |
if numpy.allclose(Tr1, 0.0) or type(Tr1)==complex: | if numpy.allclose(Tr1, 0.0) or type(Tr1)==numpy.complex_: | def calc_itls_center_of_reaction(iT, iL, iS, origin): """iT is a single float; iL[3,3]; iS[3] """ ## construct TLS tensors from isotropic TLS description T0 = numpy.array([[iT, 0.0, 0.0], [0.0, iT, 0.0], [0.0, 0.0, iT]], float) L0 = iL.copy() S0 = numpy.array([ [ 0.0, 0.0, iS[1]], [iS[0], 0.0, 0.0], [ 0.0, iS[2], 0.0] ], float) ## LSMALL is the smallest magnitude of L before it is considered 0.0 LSMALL = 0.5 * Constants.DEG2RAD2 rdict = {} rdict["T'"] = T0.copy() rdict["L'"] = L0.copy() rdict["S'"] = S0.copy() rdict["rT'"] = T0.copy() rdict["L1_eigen_val"] = 0.0 rdict["L2_eigen_val"] = 0.0 rdict["L3_eigen_val"] = 0.0 rdict["L1_rmsd"] = 0.0 rdict["L2_rmsd"] = 0.0 rdict["L3_rmsd"] = 0.0 rdict["L1_eigen_vec"] = numpy.zeros(3, float) rdict["L2_eigen_vec"] = numpy.zeros(3, float) rdict["L3_eigen_vec"] = numpy.zeros(3, float) rdict["RHO"] = numpy.zeros(3, float) rdict["COR"] = origin rdict["L1_rho"] = numpy.zeros(3, float) rdict["L2_rho"] = numpy.zeros(3, float) rdict["L3_rho"] = numpy.zeros(3, float) rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 rdict["Tr1_eigen_val"] = 0.0 rdict["Tr2_eigen_val"] = 0.0 rdict["Tr3_eigen_val"] = 0.0 rdict["Tr1_rmsd"] = 0.0 rdict["Tr2_rmsd"] = 0.0 rdict["Tr3_rmsd"] = 0.0 ## set the L tensor eigenvalues and eigenvectors (L_evals, RL) = numpy.linalg.eigenvectors(L0) L1, L2, L3 = L_evals good_L_eigens = [] if numpy.allclose(L1, 0.0) or type(L1)==complex: L1 = 0.0 else: good_L_eigens.append(0) if numpy.allclose(L2, 0.0) or type(L2)==complex: L2 = 0.0 else: good_L_eigens.append(1) if numpy.allclose(L3, 0.0) or type(L3)==complex: L3 = 0.0 else: good_L_eigens.append(2) ## no good L eigen values if len(good_L_eigens)==0: Tr1, Tr2, Tr3 = numpy.linalg.eigenvalues(T0) if numpy.allclose(Tr1, 0.0) or type(Tr1)==complex: Tr1 = 0.0 if numpy.allclose(Tr2, 0.0) or type(Tr2)==complex: Tr2 = 0.0 if numpy.allclose(Tr3, 0.0) or type(Tr3)==complex: Tr3 = 0.0 rdict["Tr1_eigen_val"] = Tr1 rdict["Tr2_eigen_val"] = Tr2 rdict["Tr3_eigen_val"] = Tr3 rdict["Tr1_rmsd"] = calc_rmsd(Tr1) rdict["Tr2_rmsd"] = calc_rmsd(Tr2) rdict["Tr3_rmsd"] = calc_rmsd(Tr3) return rdict ## one good eigen value -- reconstruct RL about it elif len(good_L_eigens)==1: i = good_L_eigens[0] evec = RL[i] RZt = numpy.transpose(AtomMath.rmatrixz(evec)) xevec = numpy.matrixmultiply(RZt, numpy.array([1.0, 0.0, 0.0], float)) yevec = numpy.matrixmultiply(RZt, numpy.array([0.0, 1.0, 0.0], float)) if i==0: RL[1] = xevec RL[2] = yevec elif i==1: RL[0] = xevec RL[2] = yevec elif i==2: RL[0] = xevec RL[1] = yevec ## two good eigen values -- reconstruct RL about them elif len(good_L_eigens)==2: i = good_L_eigens[0] j = good_L_eigens[1] xevec = AtomMath.normalize(numpy.cross(RL[i], RL[j])) for k in range(3): if k==i: continue if k==j: continue RL[k] = xevec break rdict["L1_eigen_val"] = L1 rdict["L2_eigen_val"] = L2 rdict["L3_eigen_val"] = L3 rdict["L1_rmsd"] = calc_rmsd(L1) rdict["L2_rmsd"] = calc_rmsd(L2) rdict["L3_rmsd"] = calc_rmsd(L3) rdict["L1_eigen_vec"] = RL[0].copy() rdict["L2_eigen_vec"] = RL[1].copy() rdict["L3_eigen_vec"] = RL[2].copy() ## begin tensor transformations which depend upon ## the eigenvectors of L0 being well-determined ## make sure RLt is right-handed if numpy.allclose(numpy.linalg.determinant(RL), -1.0): I = numpy.identity(3, float) I[0,0] = -1.0 RL = numpy.matrixmultiply(I, RL) if not numpy.allclose(numpy.linalg.determinant(RL), 1.0): return rdict RLt = numpy.transpose(RL) ## carrot-L tensor (tensor WRT principal axes of L) cL = numpy.matrixmultiply(numpy.matrixmultiply(RL, L0), RLt) ## carrot-T tensor (T tensor WRT principal axes of L) cT = numpy.matrixmultiply(numpy.matrixmultiply(RL, T0), RLt) ## carrot-S tensor (S tensor WRT principal axes of L) cS = numpy.matrixmultiply(numpy.matrixmultiply(RL, S0), RLt) ## ^rho: the origin-shift vector in the coordinate system of L L23 = L2 + L3 L13 = L1 + L3 L12 = L1 + L2 ## shift for L1 if not numpy.allclose(L1, 0.0) and abs(L23)>LSMALL: crho1 = (cS[1,2] - cS[2,1]) / L23 else: crho1 = 0.0 if not numpy.allclose(L2, 0.0) and abs(L13)>LSMALL: crho2 = (cS[2,0] - cS[0,2]) / L13 else: crho2 = 0.0 if not numpy.allclose(L3, 0.0) and abs(L12)>LSMALL: crho3 = (cS[0,1] - cS[1,0]) / L12 else: crho3 = 0.0 crho = numpy.array([crho1, crho2, crho3], float) ## rho: the origin-shift vector in orthogonal coordinates rho = numpy.matrixmultiply(RLt, crho) rdict["RHO"] = rho rdict["COR"] = origin + rho ## set up the origin shift matrix PRHO WRT orthogonal axes PRHO = numpy.array([ [ 0.0, rho[2], -rho[1]], [-rho[2], 0.0, rho[0]], [ rho[1], -rho[0], 0.0] ], float) ## set up the origin shift matrix cPRHO WRT libration axes cPRHO = numpy.array([ [ 0.0, crho[2], -crho[1]], [-crho[2], 0.0, crho[0]], [ crho[1], -crho[0], 0.0] ], float) ## calculate tranpose of cPRHO, ans cS cSt = numpy.transpose(cS) cPRHOt = numpy.transpose(cPRHO) ## calculate S'^ = S^ + L^*pRHOt cSp = cS + numpy.matrixmultiply(cL, cPRHOt) ## calculate T'^ = cT + cPRHO*S^ + cSt*cPRHOt + cPRHO*cL*cPRHOt * cTp = cT + numpy.matrixmultiply(cPRHO, cS) + numpy.matrixmultiply(cSt, cPRHOt) + \ numpy.matrixmultiply(numpy.matrixmultiply(cPRHO, cL), cPRHOt) ## transpose of PRHO and S PRHOt = numpy.transpose(PRHO) St = numpy.transpose(S0) ## calculate S' = S + L*PRHOt Sp = S0 + numpy.matrixmultiply(L0, PRHOt) rdict["S'"] = Sp ## calculate T' = T + PRHO*S + St*PRHOT + PRHO*L*PRHOt Tp = T0 + numpy.matrixmultiply(PRHO, S0) + numpy.matrixmultiply(St, PRHOt) + \ numpy.matrixmultiply(numpy.matrixmultiply(PRHO, L0), PRHOt) rdict["T'"] = Tp ## now calculate the TLS motion description using 3 non ## intersecting screw axes, with one ## libration axis 1 shift in the L coordinate system ## you cannot determine axis shifts from the isotropic TLS parameters cL1rho = numpy.zeros(3, float) cL2rho = numpy.zeros(3, float) cL3rho = numpy.zeros(3, float) ## libration axes shifts in the origional orthogonal ## coordinate system rdict["L1_rho"] = numpy.matrixmultiply(RLt, cL1rho) rdict["L2_rho"] = numpy.matrixmultiply(RLt, cL2rho) rdict["L3_rho"] = numpy.matrixmultiply(RLt, cL3rho) ## calculate screw pitches (A*R / R*R) = (A/R) ## no screw pitches either rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 ## rotate the newly calculated reduced-T tensor from the carrot ## coordinate system (coordinate system of L) back to the structure ## coordinate system Tiso = numpy.trace(Tp) / 3.0 rdict["rT'"] = Tiso * numpy.identity(3, float) rdict["Tr1_eigen_val"] = Tiso rdict["Tr2_eigen_val"] = Tiso rdict["Tr3_eigen_val"] = Tiso rdict["Tr1_rmsd"] = calc_rmsd(Tiso) rdict["Tr2_rmsd"] = calc_rmsd(Tiso) rdict["Tr3_rmsd"] = calc_rmsd(Tiso) return rdict |
if numpy.allclose(Tr2, 0.0) or type(Tr2)==complex: | if numpy.allclose(Tr2, 0.0) or type(Tr2)==numpy.complex_: | def calc_itls_center_of_reaction(iT, iL, iS, origin): """iT is a single float; iL[3,3]; iS[3] """ ## construct TLS tensors from isotropic TLS description T0 = numpy.array([[iT, 0.0, 0.0], [0.0, iT, 0.0], [0.0, 0.0, iT]], float) L0 = iL.copy() S0 = numpy.array([ [ 0.0, 0.0, iS[1]], [iS[0], 0.0, 0.0], [ 0.0, iS[2], 0.0] ], float) ## LSMALL is the smallest magnitude of L before it is considered 0.0 LSMALL = 0.5 * Constants.DEG2RAD2 rdict = {} rdict["T'"] = T0.copy() rdict["L'"] = L0.copy() rdict["S'"] = S0.copy() rdict["rT'"] = T0.copy() rdict["L1_eigen_val"] = 0.0 rdict["L2_eigen_val"] = 0.0 rdict["L3_eigen_val"] = 0.0 rdict["L1_rmsd"] = 0.0 rdict["L2_rmsd"] = 0.0 rdict["L3_rmsd"] = 0.0 rdict["L1_eigen_vec"] = numpy.zeros(3, float) rdict["L2_eigen_vec"] = numpy.zeros(3, float) rdict["L3_eigen_vec"] = numpy.zeros(3, float) rdict["RHO"] = numpy.zeros(3, float) rdict["COR"] = origin rdict["L1_rho"] = numpy.zeros(3, float) rdict["L2_rho"] = numpy.zeros(3, float) rdict["L3_rho"] = numpy.zeros(3, float) rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 rdict["Tr1_eigen_val"] = 0.0 rdict["Tr2_eigen_val"] = 0.0 rdict["Tr3_eigen_val"] = 0.0 rdict["Tr1_rmsd"] = 0.0 rdict["Tr2_rmsd"] = 0.0 rdict["Tr3_rmsd"] = 0.0 ## set the L tensor eigenvalues and eigenvectors (L_evals, RL) = numpy.linalg.eigenvectors(L0) L1, L2, L3 = L_evals good_L_eigens = [] if numpy.allclose(L1, 0.0) or type(L1)==complex: L1 = 0.0 else: good_L_eigens.append(0) if numpy.allclose(L2, 0.0) or type(L2)==complex: L2 = 0.0 else: good_L_eigens.append(1) if numpy.allclose(L3, 0.0) or type(L3)==complex: L3 = 0.0 else: good_L_eigens.append(2) ## no good L eigen values if len(good_L_eigens)==0: Tr1, Tr2, Tr3 = numpy.linalg.eigenvalues(T0) if numpy.allclose(Tr1, 0.0) or type(Tr1)==complex: Tr1 = 0.0 if numpy.allclose(Tr2, 0.0) or type(Tr2)==complex: Tr2 = 0.0 if numpy.allclose(Tr3, 0.0) or type(Tr3)==complex: Tr3 = 0.0 rdict["Tr1_eigen_val"] = Tr1 rdict["Tr2_eigen_val"] = Tr2 rdict["Tr3_eigen_val"] = Tr3 rdict["Tr1_rmsd"] = calc_rmsd(Tr1) rdict["Tr2_rmsd"] = calc_rmsd(Tr2) rdict["Tr3_rmsd"] = calc_rmsd(Tr3) return rdict ## one good eigen value -- reconstruct RL about it elif len(good_L_eigens)==1: i = good_L_eigens[0] evec = RL[i] RZt = numpy.transpose(AtomMath.rmatrixz(evec)) xevec = numpy.matrixmultiply(RZt, numpy.array([1.0, 0.0, 0.0], float)) yevec = numpy.matrixmultiply(RZt, numpy.array([0.0, 1.0, 0.0], float)) if i==0: RL[1] = xevec RL[2] = yevec elif i==1: RL[0] = xevec RL[2] = yevec elif i==2: RL[0] = xevec RL[1] = yevec ## two good eigen values -- reconstruct RL about them elif len(good_L_eigens)==2: i = good_L_eigens[0] j = good_L_eigens[1] xevec = AtomMath.normalize(numpy.cross(RL[i], RL[j])) for k in range(3): if k==i: continue if k==j: continue RL[k] = xevec break rdict["L1_eigen_val"] = L1 rdict["L2_eigen_val"] = L2 rdict["L3_eigen_val"] = L3 rdict["L1_rmsd"] = calc_rmsd(L1) rdict["L2_rmsd"] = calc_rmsd(L2) rdict["L3_rmsd"] = calc_rmsd(L3) rdict["L1_eigen_vec"] = RL[0].copy() rdict["L2_eigen_vec"] = RL[1].copy() rdict["L3_eigen_vec"] = RL[2].copy() ## begin tensor transformations which depend upon ## the eigenvectors of L0 being well-determined ## make sure RLt is right-handed if numpy.allclose(numpy.linalg.determinant(RL), -1.0): I = numpy.identity(3, float) I[0,0] = -1.0 RL = numpy.matrixmultiply(I, RL) if not numpy.allclose(numpy.linalg.determinant(RL), 1.0): return rdict RLt = numpy.transpose(RL) ## carrot-L tensor (tensor WRT principal axes of L) cL = numpy.matrixmultiply(numpy.matrixmultiply(RL, L0), RLt) ## carrot-T tensor (T tensor WRT principal axes of L) cT = numpy.matrixmultiply(numpy.matrixmultiply(RL, T0), RLt) ## carrot-S tensor (S tensor WRT principal axes of L) cS = numpy.matrixmultiply(numpy.matrixmultiply(RL, S0), RLt) ## ^rho: the origin-shift vector in the coordinate system of L L23 = L2 + L3 L13 = L1 + L3 L12 = L1 + L2 ## shift for L1 if not numpy.allclose(L1, 0.0) and abs(L23)>LSMALL: crho1 = (cS[1,2] - cS[2,1]) / L23 else: crho1 = 0.0 if not numpy.allclose(L2, 0.0) and abs(L13)>LSMALL: crho2 = (cS[2,0] - cS[0,2]) / L13 else: crho2 = 0.0 if not numpy.allclose(L3, 0.0) and abs(L12)>LSMALL: crho3 = (cS[0,1] - cS[1,0]) / L12 else: crho3 = 0.0 crho = numpy.array([crho1, crho2, crho3], float) ## rho: the origin-shift vector in orthogonal coordinates rho = numpy.matrixmultiply(RLt, crho) rdict["RHO"] = rho rdict["COR"] = origin + rho ## set up the origin shift matrix PRHO WRT orthogonal axes PRHO = numpy.array([ [ 0.0, rho[2], -rho[1]], [-rho[2], 0.0, rho[0]], [ rho[1], -rho[0], 0.0] ], float) ## set up the origin shift matrix cPRHO WRT libration axes cPRHO = numpy.array([ [ 0.0, crho[2], -crho[1]], [-crho[2], 0.0, crho[0]], [ crho[1], -crho[0], 0.0] ], float) ## calculate tranpose of cPRHO, ans cS cSt = numpy.transpose(cS) cPRHOt = numpy.transpose(cPRHO) ## calculate S'^ = S^ + L^*pRHOt cSp = cS + numpy.matrixmultiply(cL, cPRHOt) ## calculate T'^ = cT + cPRHO*S^ + cSt*cPRHOt + cPRHO*cL*cPRHOt * cTp = cT + numpy.matrixmultiply(cPRHO, cS) + numpy.matrixmultiply(cSt, cPRHOt) + \ numpy.matrixmultiply(numpy.matrixmultiply(cPRHO, cL), cPRHOt) ## transpose of PRHO and S PRHOt = numpy.transpose(PRHO) St = numpy.transpose(S0) ## calculate S' = S + L*PRHOt Sp = S0 + numpy.matrixmultiply(L0, PRHOt) rdict["S'"] = Sp ## calculate T' = T + PRHO*S + St*PRHOT + PRHO*L*PRHOt Tp = T0 + numpy.matrixmultiply(PRHO, S0) + numpy.matrixmultiply(St, PRHOt) + \ numpy.matrixmultiply(numpy.matrixmultiply(PRHO, L0), PRHOt) rdict["T'"] = Tp ## now calculate the TLS motion description using 3 non ## intersecting screw axes, with one ## libration axis 1 shift in the L coordinate system ## you cannot determine axis shifts from the isotropic TLS parameters cL1rho = numpy.zeros(3, float) cL2rho = numpy.zeros(3, float) cL3rho = numpy.zeros(3, float) ## libration axes shifts in the origional orthogonal ## coordinate system rdict["L1_rho"] = numpy.matrixmultiply(RLt, cL1rho) rdict["L2_rho"] = numpy.matrixmultiply(RLt, cL2rho) rdict["L3_rho"] = numpy.matrixmultiply(RLt, cL3rho) ## calculate screw pitches (A*R / R*R) = (A/R) ## no screw pitches either rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 ## rotate the newly calculated reduced-T tensor from the carrot ## coordinate system (coordinate system of L) back to the structure ## coordinate system Tiso = numpy.trace(Tp) / 3.0 rdict["rT'"] = Tiso * numpy.identity(3, float) rdict["Tr1_eigen_val"] = Tiso rdict["Tr2_eigen_val"] = Tiso rdict["Tr3_eigen_val"] = Tiso rdict["Tr1_rmsd"] = calc_rmsd(Tiso) rdict["Tr2_rmsd"] = calc_rmsd(Tiso) rdict["Tr3_rmsd"] = calc_rmsd(Tiso) return rdict |
if numpy.allclose(Tr3, 0.0) or type(Tr3)==complex: | if numpy.allclose(Tr3, 0.0) or type(Tr3)==numpy.complex_: | def calc_itls_center_of_reaction(iT, iL, iS, origin): """iT is a single float; iL[3,3]; iS[3] """ ## construct TLS tensors from isotropic TLS description T0 = numpy.array([[iT, 0.0, 0.0], [0.0, iT, 0.0], [0.0, 0.0, iT]], float) L0 = iL.copy() S0 = numpy.array([ [ 0.0, 0.0, iS[1]], [iS[0], 0.0, 0.0], [ 0.0, iS[2], 0.0] ], float) ## LSMALL is the smallest magnitude of L before it is considered 0.0 LSMALL = 0.5 * Constants.DEG2RAD2 rdict = {} rdict["T'"] = T0.copy() rdict["L'"] = L0.copy() rdict["S'"] = S0.copy() rdict["rT'"] = T0.copy() rdict["L1_eigen_val"] = 0.0 rdict["L2_eigen_val"] = 0.0 rdict["L3_eigen_val"] = 0.0 rdict["L1_rmsd"] = 0.0 rdict["L2_rmsd"] = 0.0 rdict["L3_rmsd"] = 0.0 rdict["L1_eigen_vec"] = numpy.zeros(3, float) rdict["L2_eigen_vec"] = numpy.zeros(3, float) rdict["L3_eigen_vec"] = numpy.zeros(3, float) rdict["RHO"] = numpy.zeros(3, float) rdict["COR"] = origin rdict["L1_rho"] = numpy.zeros(3, float) rdict["L2_rho"] = numpy.zeros(3, float) rdict["L3_rho"] = numpy.zeros(3, float) rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 rdict["Tr1_eigen_val"] = 0.0 rdict["Tr2_eigen_val"] = 0.0 rdict["Tr3_eigen_val"] = 0.0 rdict["Tr1_rmsd"] = 0.0 rdict["Tr2_rmsd"] = 0.0 rdict["Tr3_rmsd"] = 0.0 ## set the L tensor eigenvalues and eigenvectors (L_evals, RL) = numpy.linalg.eigenvectors(L0) L1, L2, L3 = L_evals good_L_eigens = [] if numpy.allclose(L1, 0.0) or type(L1)==complex: L1 = 0.0 else: good_L_eigens.append(0) if numpy.allclose(L2, 0.0) or type(L2)==complex: L2 = 0.0 else: good_L_eigens.append(1) if numpy.allclose(L3, 0.0) or type(L3)==complex: L3 = 0.0 else: good_L_eigens.append(2) ## no good L eigen values if len(good_L_eigens)==0: Tr1, Tr2, Tr3 = numpy.linalg.eigenvalues(T0) if numpy.allclose(Tr1, 0.0) or type(Tr1)==complex: Tr1 = 0.0 if numpy.allclose(Tr2, 0.0) or type(Tr2)==complex: Tr2 = 0.0 if numpy.allclose(Tr3, 0.0) or type(Tr3)==complex: Tr3 = 0.0 rdict["Tr1_eigen_val"] = Tr1 rdict["Tr2_eigen_val"] = Tr2 rdict["Tr3_eigen_val"] = Tr3 rdict["Tr1_rmsd"] = calc_rmsd(Tr1) rdict["Tr2_rmsd"] = calc_rmsd(Tr2) rdict["Tr3_rmsd"] = calc_rmsd(Tr3) return rdict ## one good eigen value -- reconstruct RL about it elif len(good_L_eigens)==1: i = good_L_eigens[0] evec = RL[i] RZt = numpy.transpose(AtomMath.rmatrixz(evec)) xevec = numpy.matrixmultiply(RZt, numpy.array([1.0, 0.0, 0.0], float)) yevec = numpy.matrixmultiply(RZt, numpy.array([0.0, 1.0, 0.0], float)) if i==0: RL[1] = xevec RL[2] = yevec elif i==1: RL[0] = xevec RL[2] = yevec elif i==2: RL[0] = xevec RL[1] = yevec ## two good eigen values -- reconstruct RL about them elif len(good_L_eigens)==2: i = good_L_eigens[0] j = good_L_eigens[1] xevec = AtomMath.normalize(numpy.cross(RL[i], RL[j])) for k in range(3): if k==i: continue if k==j: continue RL[k] = xevec break rdict["L1_eigen_val"] = L1 rdict["L2_eigen_val"] = L2 rdict["L3_eigen_val"] = L3 rdict["L1_rmsd"] = calc_rmsd(L1) rdict["L2_rmsd"] = calc_rmsd(L2) rdict["L3_rmsd"] = calc_rmsd(L3) rdict["L1_eigen_vec"] = RL[0].copy() rdict["L2_eigen_vec"] = RL[1].copy() rdict["L3_eigen_vec"] = RL[2].copy() ## begin tensor transformations which depend upon ## the eigenvectors of L0 being well-determined ## make sure RLt is right-handed if numpy.allclose(numpy.linalg.determinant(RL), -1.0): I = numpy.identity(3, float) I[0,0] = -1.0 RL = numpy.matrixmultiply(I, RL) if not numpy.allclose(numpy.linalg.determinant(RL), 1.0): return rdict RLt = numpy.transpose(RL) ## carrot-L tensor (tensor WRT principal axes of L) cL = numpy.matrixmultiply(numpy.matrixmultiply(RL, L0), RLt) ## carrot-T tensor (T tensor WRT principal axes of L) cT = numpy.matrixmultiply(numpy.matrixmultiply(RL, T0), RLt) ## carrot-S tensor (S tensor WRT principal axes of L) cS = numpy.matrixmultiply(numpy.matrixmultiply(RL, S0), RLt) ## ^rho: the origin-shift vector in the coordinate system of L L23 = L2 + L3 L13 = L1 + L3 L12 = L1 + L2 ## shift for L1 if not numpy.allclose(L1, 0.0) and abs(L23)>LSMALL: crho1 = (cS[1,2] - cS[2,1]) / L23 else: crho1 = 0.0 if not numpy.allclose(L2, 0.0) and abs(L13)>LSMALL: crho2 = (cS[2,0] - cS[0,2]) / L13 else: crho2 = 0.0 if not numpy.allclose(L3, 0.0) and abs(L12)>LSMALL: crho3 = (cS[0,1] - cS[1,0]) / L12 else: crho3 = 0.0 crho = numpy.array([crho1, crho2, crho3], float) ## rho: the origin-shift vector in orthogonal coordinates rho = numpy.matrixmultiply(RLt, crho) rdict["RHO"] = rho rdict["COR"] = origin + rho ## set up the origin shift matrix PRHO WRT orthogonal axes PRHO = numpy.array([ [ 0.0, rho[2], -rho[1]], [-rho[2], 0.0, rho[0]], [ rho[1], -rho[0], 0.0] ], float) ## set up the origin shift matrix cPRHO WRT libration axes cPRHO = numpy.array([ [ 0.0, crho[2], -crho[1]], [-crho[2], 0.0, crho[0]], [ crho[1], -crho[0], 0.0] ], float) ## calculate tranpose of cPRHO, ans cS cSt = numpy.transpose(cS) cPRHOt = numpy.transpose(cPRHO) ## calculate S'^ = S^ + L^*pRHOt cSp = cS + numpy.matrixmultiply(cL, cPRHOt) ## calculate T'^ = cT + cPRHO*S^ + cSt*cPRHOt + cPRHO*cL*cPRHOt * cTp = cT + numpy.matrixmultiply(cPRHO, cS) + numpy.matrixmultiply(cSt, cPRHOt) + \ numpy.matrixmultiply(numpy.matrixmultiply(cPRHO, cL), cPRHOt) ## transpose of PRHO and S PRHOt = numpy.transpose(PRHO) St = numpy.transpose(S0) ## calculate S' = S + L*PRHOt Sp = S0 + numpy.matrixmultiply(L0, PRHOt) rdict["S'"] = Sp ## calculate T' = T + PRHO*S + St*PRHOT + PRHO*L*PRHOt Tp = T0 + numpy.matrixmultiply(PRHO, S0) + numpy.matrixmultiply(St, PRHOt) + \ numpy.matrixmultiply(numpy.matrixmultiply(PRHO, L0), PRHOt) rdict["T'"] = Tp ## now calculate the TLS motion description using 3 non ## intersecting screw axes, with one ## libration axis 1 shift in the L coordinate system ## you cannot determine axis shifts from the isotropic TLS parameters cL1rho = numpy.zeros(3, float) cL2rho = numpy.zeros(3, float) cL3rho = numpy.zeros(3, float) ## libration axes shifts in the origional orthogonal ## coordinate system rdict["L1_rho"] = numpy.matrixmultiply(RLt, cL1rho) rdict["L2_rho"] = numpy.matrixmultiply(RLt, cL2rho) rdict["L3_rho"] = numpy.matrixmultiply(RLt, cL3rho) ## calculate screw pitches (A*R / R*R) = (A/R) ## no screw pitches either rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 ## rotate the newly calculated reduced-T tensor from the carrot ## coordinate system (coordinate system of L) back to the structure ## coordinate system Tiso = numpy.trace(Tp) / 3.0 rdict["rT'"] = Tiso * numpy.identity(3, float) rdict["Tr1_eigen_val"] = Tiso rdict["Tr2_eigen_val"] = Tiso rdict["Tr3_eigen_val"] = Tiso rdict["Tr1_rmsd"] = calc_rmsd(Tiso) rdict["Tr2_rmsd"] = calc_rmsd(Tiso) rdict["Tr3_rmsd"] = calc_rmsd(Tiso) return rdict |
if numpy.allclose(L1, 0.0) or type(L1)==complex: | if numpy.allclose(L1, 0.0) or type(L1)==numpy.complex_: | def calc_TLS_center_of_reaction(T0, L0, S0, origin): """Calculate new tensors based on the center for reaction. This method returns a dictionary of the calculations: T^: T tensor in the coordinate system of L L^: L tensor in the coordinate system of L S^: S tensor in the coordinate system of L COR: Center of Reaction T',S',L': T,L,S tensors in origonal coordinate system with the origin shifted to the center of reaction. """ ## LSMALL is the smallest magnitude of L before it is considered 0.0 LSMALL = 0.5 * Constants.DEG2RAD2 rdict = {} rdict["T'"] = T0.copy() rdict["L'"] = L0.copy() rdict["S'"] = S0.copy() rdict["rT'"] = T0.copy() rdict["L1_eigen_val"] = 0.0 rdict["L2_eigen_val"] = 0.0 rdict["L3_eigen_val"] = 0.0 rdict["L1_rmsd"] = 0.0 rdict["L2_rmsd"] = 0.0 rdict["L3_rmsd"] = 0.0 rdict["L1_eigen_vec"] = numpy.zeros(3, float) rdict["L2_eigen_vec"] = numpy.zeros(3, float) rdict["L3_eigen_vec"] = numpy.zeros(3, float) rdict["RHO"] = numpy.zeros(3, float) rdict["COR"] = origin rdict["L1_rho"] = numpy.zeros(3, float) rdict["L2_rho"] = numpy.zeros(3, float) rdict["L3_rho"] = numpy.zeros(3, float) rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 rdict["Tr1_eigen_val"] = 0.0 rdict["Tr2_eigen_val"] = 0.0 rdict["Tr3_eigen_val"] = 0.0 rdict["Tr1_rmsd"] = 0.0 rdict["Tr2_rmsd"] = 0.0 rdict["Tr3_rmsd"] = 0.0 ## set the L tensor eigenvalues and eigenvectors (L_evals, RL) = numpy.linalg.eigenvectors(L0) L1, L2, L3 = L_evals good_L_eigens = [] if numpy.allclose(L1, 0.0) or type(L1)==complex: L1 = 0.0 else: good_L_eigens.append(0) if numpy.allclose(L2, 0.0) or type(L2)==complex: L2 = 0.0 else: good_L_eigens.append(1) if numpy.allclose(L3, 0.0) or type(L3)==complex: L3 = 0.0 else: good_L_eigens.append(2) ## no good L eigen values if len(good_L_eigens)==0: return rdict ## one good eigen value -- reconstruct RL about it elif len(good_L_eigens)==1: i = good_L_eigens[0] evec = RL[i] RZt = numpy.transpose(AtomMath.rmatrixz(evec)) xevec = numpy.matrixmultiply(RZt, numpy.array([1.0, 0.0, 0.0], float)) yevec = numpy.matrixmultiply(RZt, numpy.array([0.0, 1.0, 0.0], float)) if i==0: RL[1] = xevec RL[2] = yevec elif i==1: RL[0] = xevec RL[2] = yevec elif i==2: RL[0] = xevec RL[1] = yevec ## two good eigen values -- reconstruct RL about them elif len(good_L_eigens)==2: i = good_L_eigens[0] j = good_L_eigens[1] xevec = AtomMath.normalize(numpy.cross(RL[i], RL[j])) for k in range(3): if k==i: continue if k==j: continue RL[k] = xevec break rdict["L1_eigen_val"] = L1 rdict["L2_eigen_val"] = L2 rdict["L3_eigen_val"] = L3 rdict["L1_rmsd"] = calc_rmsd(L1) rdict["L2_rmsd"] = calc_rmsd(L2) rdict["L3_rmsd"] = calc_rmsd(L3) rdict["L1_eigen_vec"] = RL[0].copy() rdict["L2_eigen_vec"] = RL[1].copy() rdict["L3_eigen_vec"] = RL[2].copy() ## begin tensor transformations which depend upon ## the eigenvectors of L0 being well-determined ## make sure RLt is right-handed if numpy.allclose(numpy.linalg.determinant(RL), -1.0): I = numpy.identity(3, float) I[0,0] = -1.0 RL = numpy.matrixmultiply(I, RL) if not numpy.allclose(numpy.linalg.determinant(RL), 1.0): return rdict RLt = numpy.transpose(RL) ## carrot-L tensor (tensor WRT principal axes of L) cL = numpy.matrixmultiply(numpy.matrixmultiply(RL, L0), RLt) rdict["L^"] = cL.copy() ## carrot-T tensor (T tensor WRT principal axes of L) cT = numpy.matrixmultiply(numpy.matrixmultiply(RL, T0), RLt) rdict["T^"] = cT.copy() ## carrot-S tensor (S tensor WRT principal axes of L) cS = numpy.matrixmultiply(numpy.matrixmultiply(RL, S0), RLt) rdict["S^"] = cS.copy() ## ^rho: the origin-shift vector in the coordinate system of L L23 = L2 + L3 L13 = L1 + L3 L12 = L1 + L2 ## shift for L1 if not numpy.allclose(L1, 0.0) and abs(L23)>LSMALL: crho1 = (cS[1,2] - cS[2,1]) / L23 else: crho1 = 0.0 if not numpy.allclose(L2, 0.0) and abs(L13)>LSMALL: crho2 = (cS[2,0] - cS[0,2]) / L13 else: crho2 = 0.0 if not numpy.allclose(L3, 0.0) and abs(L12)>LSMALL: crho3 = (cS[0,1] - cS[1,0]) / L12 else: crho3 = 0.0 crho = numpy.array([crho1, crho2, crho3], float) rdict["RHO^"] = crho.copy() ## rho: the origin-shift vector in orthogonal coordinates rho = numpy.matrixmultiply(RLt, crho) rdict["RHO"] = rho rdict["COR"] = origin + rho ## set up the origin shift matrix PRHO WRT orthogonal axes PRHO = numpy.array([ [ 0.0, rho[2], -rho[1]], [-rho[2], 0.0, rho[0]], [ rho[1], -rho[0], 0.0] ], float) ## set up the origin shift matrix cPRHO WRT libration axes cPRHO = numpy.array([ [ 0.0, crho[2], -crho[1]], [-crho[2], 0.0, crho[0]], [ crho[1], -crho[0], 0.0] ], float) ## calculate tranpose of cPRHO, ans cS cSt = numpy.transpose(cS) cPRHOt = numpy.transpose(cPRHO) rdict["L'^"] = cL.copy() ## calculate S'^ = S^ + L^*pRHOt cSp = cS + numpy.matrixmultiply(cL, cPRHOt) rdict["S'^"] = cSp.copy() ## calculate T'^ = cT + cPRHO*S^ + cSt*cPRHOt + cPRHO*cL*cPRHOt * cTp = cT + numpy.matrixmultiply(cPRHO, cS) + numpy.matrixmultiply(cSt, cPRHOt) +\ numpy.matrixmultiply(numpy.matrixmultiply(cPRHO, cL), cPRHOt) rdict["T'^"] = cTp.copy() ## transpose of PRHO and S PRHOt = numpy.transpose(PRHO) St = numpy.transpose(S0) ## calculate S' = S + L*PRHOt Sp = S0 + numpy.matrixmultiply(L0, PRHOt) rdict["S'"] = Sp ## calculate T' = T + PRHO*S + St*PRHOT + PRHO*L*PRHOt Tp = T0 + numpy.matrixmultiply(PRHO, S0) + numpy.matrixmultiply(St, PRHOt) +\ numpy.matrixmultiply(numpy.matrixmultiply(PRHO, L0), PRHOt) rdict["T'"] = Tp ## now calculate the TLS motion description using 3 non ## intersecting screw axes, with one ## libration axis 1 shift in the L coordinate system if abs(L1)>LSMALL: cL1rho = numpy.array([0.0, -cSp[0,2]/L1, cSp[0,1]/L1], float) else: cL1rho = numpy.zeros(3, float) ## libration axis 2 shift in the L coordinate system if abs(L2)>LSMALL: cL2rho = numpy.array([cSp[1,2]/L2, 0.0, -cSp[1,0]/L2], float) else: cL2rho = numpy.zeros(3, float) ## libration axis 2 shift in the L coordinate system if abs(L3)>LSMALL: cL3rho = numpy.array([-cSp[2,1]/L3, cSp[2,0]/L3, 0.0], float) else: cL3rho = numpy.zeros(3, float) ## libration axes shifts in the origional orthogonal ## coordinate system rdict["L1_rho"] = numpy.matrixmultiply(RLt, cL1rho) rdict["L2_rho"] = numpy.matrixmultiply(RLt, cL2rho) rdict["L3_rho"] = numpy.matrixmultiply(RLt, cL3rho) ## calculate screw pitches (A*R / R*R) = (A/R) if abs(L1)>LSMALL: rdict["L1_pitch"] = cS[0,0]/L1 else: rdict["L1_pitch"] = 0.0 if L2>LSMALL: rdict["L2_pitch"] = cS[1,1]/L2 else: rdict["L2_pitch"] = 0.0 if L3>LSMALL: rdict["L3_pitch"] = cS[2,2]/L3 else: rdict["L3_pitch"] = 0.0 ## now calculate the reduction in T for the screw rotation axes cTred = cT.copy() for i in (0, 1, 2): for k in (0, 1, 2): if i==k: continue if abs(cL[k,k])>LSMALL: cTred[i,i] -= (cS[k,i]**2) / cL[k,k] for i in (0, 1, 2): for j in (0, 1, 2): for k in (0, 1, 2): if j==i: continue if abs(cL[k,k])>LSMALL: cTred[i,j] -= (cS[k,i]*cS[k,j]) / cL[k,k] ## rotate the newly calculated reduced-T tensor from the carrot ## coordinate system (coordinate system of L) back to the structure ## coordinate system Tr = numpy.matrixmultiply(numpy.matrixmultiply(RLt, cTred), RL) rdict["rT'"] = Tr Tr1, Tr2, Tr3 = numpy.linalg.eigenvalues(Tr) if numpy.allclose(Tr1, 0.0) or type(Tr1)==complex: Tr1 = 0.0 if numpy.allclose(Tr2, 0.0) or type(Tr2)==complex: Tr2 = 0.0 if numpy.allclose(Tr3, 0.0) or type(Tr3)==complex: Tr3 = 0.0 rdict["Tr1_eigen_val"] = Tr1 rdict["Tr2_eigen_val"] = Tr2 rdict["Tr3_eigen_val"] = Tr3 rdict["Tr1_rmsd"] = calc_rmsd(Tr1) rdict["Tr2_rmsd"] = calc_rmsd(Tr2) rdict["Tr3_rmsd"] = calc_rmsd(Tr3) return rdict |
if numpy.allclose(L2, 0.0) or type(L2)==complex: | if numpy.allclose(L2, 0.0) or type(L2)==numpy.complex_: | def calc_TLS_center_of_reaction(T0, L0, S0, origin): """Calculate new tensors based on the center for reaction. This method returns a dictionary of the calculations: T^: T tensor in the coordinate system of L L^: L tensor in the coordinate system of L S^: S tensor in the coordinate system of L COR: Center of Reaction T',S',L': T,L,S tensors in origonal coordinate system with the origin shifted to the center of reaction. """ ## LSMALL is the smallest magnitude of L before it is considered 0.0 LSMALL = 0.5 * Constants.DEG2RAD2 rdict = {} rdict["T'"] = T0.copy() rdict["L'"] = L0.copy() rdict["S'"] = S0.copy() rdict["rT'"] = T0.copy() rdict["L1_eigen_val"] = 0.0 rdict["L2_eigen_val"] = 0.0 rdict["L3_eigen_val"] = 0.0 rdict["L1_rmsd"] = 0.0 rdict["L2_rmsd"] = 0.0 rdict["L3_rmsd"] = 0.0 rdict["L1_eigen_vec"] = numpy.zeros(3, float) rdict["L2_eigen_vec"] = numpy.zeros(3, float) rdict["L3_eigen_vec"] = numpy.zeros(3, float) rdict["RHO"] = numpy.zeros(3, float) rdict["COR"] = origin rdict["L1_rho"] = numpy.zeros(3, float) rdict["L2_rho"] = numpy.zeros(3, float) rdict["L3_rho"] = numpy.zeros(3, float) rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 rdict["Tr1_eigen_val"] = 0.0 rdict["Tr2_eigen_val"] = 0.0 rdict["Tr3_eigen_val"] = 0.0 rdict["Tr1_rmsd"] = 0.0 rdict["Tr2_rmsd"] = 0.0 rdict["Tr3_rmsd"] = 0.0 ## set the L tensor eigenvalues and eigenvectors (L_evals, RL) = numpy.linalg.eigenvectors(L0) L1, L2, L3 = L_evals good_L_eigens = [] if numpy.allclose(L1, 0.0) or type(L1)==complex: L1 = 0.0 else: good_L_eigens.append(0) if numpy.allclose(L2, 0.0) or type(L2)==complex: L2 = 0.0 else: good_L_eigens.append(1) if numpy.allclose(L3, 0.0) or type(L3)==complex: L3 = 0.0 else: good_L_eigens.append(2) ## no good L eigen values if len(good_L_eigens)==0: return rdict ## one good eigen value -- reconstruct RL about it elif len(good_L_eigens)==1: i = good_L_eigens[0] evec = RL[i] RZt = numpy.transpose(AtomMath.rmatrixz(evec)) xevec = numpy.matrixmultiply(RZt, numpy.array([1.0, 0.0, 0.0], float)) yevec = numpy.matrixmultiply(RZt, numpy.array([0.0, 1.0, 0.0], float)) if i==0: RL[1] = xevec RL[2] = yevec elif i==1: RL[0] = xevec RL[2] = yevec elif i==2: RL[0] = xevec RL[1] = yevec ## two good eigen values -- reconstruct RL about them elif len(good_L_eigens)==2: i = good_L_eigens[0] j = good_L_eigens[1] xevec = AtomMath.normalize(numpy.cross(RL[i], RL[j])) for k in range(3): if k==i: continue if k==j: continue RL[k] = xevec break rdict["L1_eigen_val"] = L1 rdict["L2_eigen_val"] = L2 rdict["L3_eigen_val"] = L3 rdict["L1_rmsd"] = calc_rmsd(L1) rdict["L2_rmsd"] = calc_rmsd(L2) rdict["L3_rmsd"] = calc_rmsd(L3) rdict["L1_eigen_vec"] = RL[0].copy() rdict["L2_eigen_vec"] = RL[1].copy() rdict["L3_eigen_vec"] = RL[2].copy() ## begin tensor transformations which depend upon ## the eigenvectors of L0 being well-determined ## make sure RLt is right-handed if numpy.allclose(numpy.linalg.determinant(RL), -1.0): I = numpy.identity(3, float) I[0,0] = -1.0 RL = numpy.matrixmultiply(I, RL) if not numpy.allclose(numpy.linalg.determinant(RL), 1.0): return rdict RLt = numpy.transpose(RL) ## carrot-L tensor (tensor WRT principal axes of L) cL = numpy.matrixmultiply(numpy.matrixmultiply(RL, L0), RLt) rdict["L^"] = cL.copy() ## carrot-T tensor (T tensor WRT principal axes of L) cT = numpy.matrixmultiply(numpy.matrixmultiply(RL, T0), RLt) rdict["T^"] = cT.copy() ## carrot-S tensor (S tensor WRT principal axes of L) cS = numpy.matrixmultiply(numpy.matrixmultiply(RL, S0), RLt) rdict["S^"] = cS.copy() ## ^rho: the origin-shift vector in the coordinate system of L L23 = L2 + L3 L13 = L1 + L3 L12 = L1 + L2 ## shift for L1 if not numpy.allclose(L1, 0.0) and abs(L23)>LSMALL: crho1 = (cS[1,2] - cS[2,1]) / L23 else: crho1 = 0.0 if not numpy.allclose(L2, 0.0) and abs(L13)>LSMALL: crho2 = (cS[2,0] - cS[0,2]) / L13 else: crho2 = 0.0 if not numpy.allclose(L3, 0.0) and abs(L12)>LSMALL: crho3 = (cS[0,1] - cS[1,0]) / L12 else: crho3 = 0.0 crho = numpy.array([crho1, crho2, crho3], float) rdict["RHO^"] = crho.copy() ## rho: the origin-shift vector in orthogonal coordinates rho = numpy.matrixmultiply(RLt, crho) rdict["RHO"] = rho rdict["COR"] = origin + rho ## set up the origin shift matrix PRHO WRT orthogonal axes PRHO = numpy.array([ [ 0.0, rho[2], -rho[1]], [-rho[2], 0.0, rho[0]], [ rho[1], -rho[0], 0.0] ], float) ## set up the origin shift matrix cPRHO WRT libration axes cPRHO = numpy.array([ [ 0.0, crho[2], -crho[1]], [-crho[2], 0.0, crho[0]], [ crho[1], -crho[0], 0.0] ], float) ## calculate tranpose of cPRHO, ans cS cSt = numpy.transpose(cS) cPRHOt = numpy.transpose(cPRHO) rdict["L'^"] = cL.copy() ## calculate S'^ = S^ + L^*pRHOt cSp = cS + numpy.matrixmultiply(cL, cPRHOt) rdict["S'^"] = cSp.copy() ## calculate T'^ = cT + cPRHO*S^ + cSt*cPRHOt + cPRHO*cL*cPRHOt * cTp = cT + numpy.matrixmultiply(cPRHO, cS) + numpy.matrixmultiply(cSt, cPRHOt) +\ numpy.matrixmultiply(numpy.matrixmultiply(cPRHO, cL), cPRHOt) rdict["T'^"] = cTp.copy() ## transpose of PRHO and S PRHOt = numpy.transpose(PRHO) St = numpy.transpose(S0) ## calculate S' = S + L*PRHOt Sp = S0 + numpy.matrixmultiply(L0, PRHOt) rdict["S'"] = Sp ## calculate T' = T + PRHO*S + St*PRHOT + PRHO*L*PRHOt Tp = T0 + numpy.matrixmultiply(PRHO, S0) + numpy.matrixmultiply(St, PRHOt) +\ numpy.matrixmultiply(numpy.matrixmultiply(PRHO, L0), PRHOt) rdict["T'"] = Tp ## now calculate the TLS motion description using 3 non ## intersecting screw axes, with one ## libration axis 1 shift in the L coordinate system if abs(L1)>LSMALL: cL1rho = numpy.array([0.0, -cSp[0,2]/L1, cSp[0,1]/L1], float) else: cL1rho = numpy.zeros(3, float) ## libration axis 2 shift in the L coordinate system if abs(L2)>LSMALL: cL2rho = numpy.array([cSp[1,2]/L2, 0.0, -cSp[1,0]/L2], float) else: cL2rho = numpy.zeros(3, float) ## libration axis 2 shift in the L coordinate system if abs(L3)>LSMALL: cL3rho = numpy.array([-cSp[2,1]/L3, cSp[2,0]/L3, 0.0], float) else: cL3rho = numpy.zeros(3, float) ## libration axes shifts in the origional orthogonal ## coordinate system rdict["L1_rho"] = numpy.matrixmultiply(RLt, cL1rho) rdict["L2_rho"] = numpy.matrixmultiply(RLt, cL2rho) rdict["L3_rho"] = numpy.matrixmultiply(RLt, cL3rho) ## calculate screw pitches (A*R / R*R) = (A/R) if abs(L1)>LSMALL: rdict["L1_pitch"] = cS[0,0]/L1 else: rdict["L1_pitch"] = 0.0 if L2>LSMALL: rdict["L2_pitch"] = cS[1,1]/L2 else: rdict["L2_pitch"] = 0.0 if L3>LSMALL: rdict["L3_pitch"] = cS[2,2]/L3 else: rdict["L3_pitch"] = 0.0 ## now calculate the reduction in T for the screw rotation axes cTred = cT.copy() for i in (0, 1, 2): for k in (0, 1, 2): if i==k: continue if abs(cL[k,k])>LSMALL: cTred[i,i] -= (cS[k,i]**2) / cL[k,k] for i in (0, 1, 2): for j in (0, 1, 2): for k in (0, 1, 2): if j==i: continue if abs(cL[k,k])>LSMALL: cTred[i,j] -= (cS[k,i]*cS[k,j]) / cL[k,k] ## rotate the newly calculated reduced-T tensor from the carrot ## coordinate system (coordinate system of L) back to the structure ## coordinate system Tr = numpy.matrixmultiply(numpy.matrixmultiply(RLt, cTred), RL) rdict["rT'"] = Tr Tr1, Tr2, Tr3 = numpy.linalg.eigenvalues(Tr) if numpy.allclose(Tr1, 0.0) or type(Tr1)==complex: Tr1 = 0.0 if numpy.allclose(Tr2, 0.0) or type(Tr2)==complex: Tr2 = 0.0 if numpy.allclose(Tr3, 0.0) or type(Tr3)==complex: Tr3 = 0.0 rdict["Tr1_eigen_val"] = Tr1 rdict["Tr2_eigen_val"] = Tr2 rdict["Tr3_eigen_val"] = Tr3 rdict["Tr1_rmsd"] = calc_rmsd(Tr1) rdict["Tr2_rmsd"] = calc_rmsd(Tr2) rdict["Tr3_rmsd"] = calc_rmsd(Tr3) return rdict |
if numpy.allclose(L3, 0.0) or type(L3)==complex: | if numpy.allclose(L3, 0.0) or type(L3)==numpy.complex_: | def calc_TLS_center_of_reaction(T0, L0, S0, origin): """Calculate new tensors based on the center for reaction. This method returns a dictionary of the calculations: T^: T tensor in the coordinate system of L L^: L tensor in the coordinate system of L S^: S tensor in the coordinate system of L COR: Center of Reaction T',S',L': T,L,S tensors in origonal coordinate system with the origin shifted to the center of reaction. """ ## LSMALL is the smallest magnitude of L before it is considered 0.0 LSMALL = 0.5 * Constants.DEG2RAD2 rdict = {} rdict["T'"] = T0.copy() rdict["L'"] = L0.copy() rdict["S'"] = S0.copy() rdict["rT'"] = T0.copy() rdict["L1_eigen_val"] = 0.0 rdict["L2_eigen_val"] = 0.0 rdict["L3_eigen_val"] = 0.0 rdict["L1_rmsd"] = 0.0 rdict["L2_rmsd"] = 0.0 rdict["L3_rmsd"] = 0.0 rdict["L1_eigen_vec"] = numpy.zeros(3, float) rdict["L2_eigen_vec"] = numpy.zeros(3, float) rdict["L3_eigen_vec"] = numpy.zeros(3, float) rdict["RHO"] = numpy.zeros(3, float) rdict["COR"] = origin rdict["L1_rho"] = numpy.zeros(3, float) rdict["L2_rho"] = numpy.zeros(3, float) rdict["L3_rho"] = numpy.zeros(3, float) rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 rdict["Tr1_eigen_val"] = 0.0 rdict["Tr2_eigen_val"] = 0.0 rdict["Tr3_eigen_val"] = 0.0 rdict["Tr1_rmsd"] = 0.0 rdict["Tr2_rmsd"] = 0.0 rdict["Tr3_rmsd"] = 0.0 ## set the L tensor eigenvalues and eigenvectors (L_evals, RL) = numpy.linalg.eigenvectors(L0) L1, L2, L3 = L_evals good_L_eigens = [] if numpy.allclose(L1, 0.0) or type(L1)==complex: L1 = 0.0 else: good_L_eigens.append(0) if numpy.allclose(L2, 0.0) or type(L2)==complex: L2 = 0.0 else: good_L_eigens.append(1) if numpy.allclose(L3, 0.0) or type(L3)==complex: L3 = 0.0 else: good_L_eigens.append(2) ## no good L eigen values if len(good_L_eigens)==0: return rdict ## one good eigen value -- reconstruct RL about it elif len(good_L_eigens)==1: i = good_L_eigens[0] evec = RL[i] RZt = numpy.transpose(AtomMath.rmatrixz(evec)) xevec = numpy.matrixmultiply(RZt, numpy.array([1.0, 0.0, 0.0], float)) yevec = numpy.matrixmultiply(RZt, numpy.array([0.0, 1.0, 0.0], float)) if i==0: RL[1] = xevec RL[2] = yevec elif i==1: RL[0] = xevec RL[2] = yevec elif i==2: RL[0] = xevec RL[1] = yevec ## two good eigen values -- reconstruct RL about them elif len(good_L_eigens)==2: i = good_L_eigens[0] j = good_L_eigens[1] xevec = AtomMath.normalize(numpy.cross(RL[i], RL[j])) for k in range(3): if k==i: continue if k==j: continue RL[k] = xevec break rdict["L1_eigen_val"] = L1 rdict["L2_eigen_val"] = L2 rdict["L3_eigen_val"] = L3 rdict["L1_rmsd"] = calc_rmsd(L1) rdict["L2_rmsd"] = calc_rmsd(L2) rdict["L3_rmsd"] = calc_rmsd(L3) rdict["L1_eigen_vec"] = RL[0].copy() rdict["L2_eigen_vec"] = RL[1].copy() rdict["L3_eigen_vec"] = RL[2].copy() ## begin tensor transformations which depend upon ## the eigenvectors of L0 being well-determined ## make sure RLt is right-handed if numpy.allclose(numpy.linalg.determinant(RL), -1.0): I = numpy.identity(3, float) I[0,0] = -1.0 RL = numpy.matrixmultiply(I, RL) if not numpy.allclose(numpy.linalg.determinant(RL), 1.0): return rdict RLt = numpy.transpose(RL) ## carrot-L tensor (tensor WRT principal axes of L) cL = numpy.matrixmultiply(numpy.matrixmultiply(RL, L0), RLt) rdict["L^"] = cL.copy() ## carrot-T tensor (T tensor WRT principal axes of L) cT = numpy.matrixmultiply(numpy.matrixmultiply(RL, T0), RLt) rdict["T^"] = cT.copy() ## carrot-S tensor (S tensor WRT principal axes of L) cS = numpy.matrixmultiply(numpy.matrixmultiply(RL, S0), RLt) rdict["S^"] = cS.copy() ## ^rho: the origin-shift vector in the coordinate system of L L23 = L2 + L3 L13 = L1 + L3 L12 = L1 + L2 ## shift for L1 if not numpy.allclose(L1, 0.0) and abs(L23)>LSMALL: crho1 = (cS[1,2] - cS[2,1]) / L23 else: crho1 = 0.0 if not numpy.allclose(L2, 0.0) and abs(L13)>LSMALL: crho2 = (cS[2,0] - cS[0,2]) / L13 else: crho2 = 0.0 if not numpy.allclose(L3, 0.0) and abs(L12)>LSMALL: crho3 = (cS[0,1] - cS[1,0]) / L12 else: crho3 = 0.0 crho = numpy.array([crho1, crho2, crho3], float) rdict["RHO^"] = crho.copy() ## rho: the origin-shift vector in orthogonal coordinates rho = numpy.matrixmultiply(RLt, crho) rdict["RHO"] = rho rdict["COR"] = origin + rho ## set up the origin shift matrix PRHO WRT orthogonal axes PRHO = numpy.array([ [ 0.0, rho[2], -rho[1]], [-rho[2], 0.0, rho[0]], [ rho[1], -rho[0], 0.0] ], float) ## set up the origin shift matrix cPRHO WRT libration axes cPRHO = numpy.array([ [ 0.0, crho[2], -crho[1]], [-crho[2], 0.0, crho[0]], [ crho[1], -crho[0], 0.0] ], float) ## calculate tranpose of cPRHO, ans cS cSt = numpy.transpose(cS) cPRHOt = numpy.transpose(cPRHO) rdict["L'^"] = cL.copy() ## calculate S'^ = S^ + L^*pRHOt cSp = cS + numpy.matrixmultiply(cL, cPRHOt) rdict["S'^"] = cSp.copy() ## calculate T'^ = cT + cPRHO*S^ + cSt*cPRHOt + cPRHO*cL*cPRHOt * cTp = cT + numpy.matrixmultiply(cPRHO, cS) + numpy.matrixmultiply(cSt, cPRHOt) +\ numpy.matrixmultiply(numpy.matrixmultiply(cPRHO, cL), cPRHOt) rdict["T'^"] = cTp.copy() ## transpose of PRHO and S PRHOt = numpy.transpose(PRHO) St = numpy.transpose(S0) ## calculate S' = S + L*PRHOt Sp = S0 + numpy.matrixmultiply(L0, PRHOt) rdict["S'"] = Sp ## calculate T' = T + PRHO*S + St*PRHOT + PRHO*L*PRHOt Tp = T0 + numpy.matrixmultiply(PRHO, S0) + numpy.matrixmultiply(St, PRHOt) +\ numpy.matrixmultiply(numpy.matrixmultiply(PRHO, L0), PRHOt) rdict["T'"] = Tp ## now calculate the TLS motion description using 3 non ## intersecting screw axes, with one ## libration axis 1 shift in the L coordinate system if abs(L1)>LSMALL: cL1rho = numpy.array([0.0, -cSp[0,2]/L1, cSp[0,1]/L1], float) else: cL1rho = numpy.zeros(3, float) ## libration axis 2 shift in the L coordinate system if abs(L2)>LSMALL: cL2rho = numpy.array([cSp[1,2]/L2, 0.0, -cSp[1,0]/L2], float) else: cL2rho = numpy.zeros(3, float) ## libration axis 2 shift in the L coordinate system if abs(L3)>LSMALL: cL3rho = numpy.array([-cSp[2,1]/L3, cSp[2,0]/L3, 0.0], float) else: cL3rho = numpy.zeros(3, float) ## libration axes shifts in the origional orthogonal ## coordinate system rdict["L1_rho"] = numpy.matrixmultiply(RLt, cL1rho) rdict["L2_rho"] = numpy.matrixmultiply(RLt, cL2rho) rdict["L3_rho"] = numpy.matrixmultiply(RLt, cL3rho) ## calculate screw pitches (A*R / R*R) = (A/R) if abs(L1)>LSMALL: rdict["L1_pitch"] = cS[0,0]/L1 else: rdict["L1_pitch"] = 0.0 if L2>LSMALL: rdict["L2_pitch"] = cS[1,1]/L2 else: rdict["L2_pitch"] = 0.0 if L3>LSMALL: rdict["L3_pitch"] = cS[2,2]/L3 else: rdict["L3_pitch"] = 0.0 ## now calculate the reduction in T for the screw rotation axes cTred = cT.copy() for i in (0, 1, 2): for k in (0, 1, 2): if i==k: continue if abs(cL[k,k])>LSMALL: cTred[i,i] -= (cS[k,i]**2) / cL[k,k] for i in (0, 1, 2): for j in (0, 1, 2): for k in (0, 1, 2): if j==i: continue if abs(cL[k,k])>LSMALL: cTred[i,j] -= (cS[k,i]*cS[k,j]) / cL[k,k] ## rotate the newly calculated reduced-T tensor from the carrot ## coordinate system (coordinate system of L) back to the structure ## coordinate system Tr = numpy.matrixmultiply(numpy.matrixmultiply(RLt, cTred), RL) rdict["rT'"] = Tr Tr1, Tr2, Tr3 = numpy.linalg.eigenvalues(Tr) if numpy.allclose(Tr1, 0.0) or type(Tr1)==complex: Tr1 = 0.0 if numpy.allclose(Tr2, 0.0) or type(Tr2)==complex: Tr2 = 0.0 if numpy.allclose(Tr3, 0.0) or type(Tr3)==complex: Tr3 = 0.0 rdict["Tr1_eigen_val"] = Tr1 rdict["Tr2_eigen_val"] = Tr2 rdict["Tr3_eigen_val"] = Tr3 rdict["Tr1_rmsd"] = calc_rmsd(Tr1) rdict["Tr2_rmsd"] = calc_rmsd(Tr2) rdict["Tr3_rmsd"] = calc_rmsd(Tr3) return rdict |
if numpy.allclose(Tr1, 0.0) or type(Tr1)==complex: | if numpy.allclose(Tr1, 0.0) or type(Tr1)==numpy.complex_: | def calc_TLS_center_of_reaction(T0, L0, S0, origin): """Calculate new tensors based on the center for reaction. This method returns a dictionary of the calculations: T^: T tensor in the coordinate system of L L^: L tensor in the coordinate system of L S^: S tensor in the coordinate system of L COR: Center of Reaction T',S',L': T,L,S tensors in origonal coordinate system with the origin shifted to the center of reaction. """ ## LSMALL is the smallest magnitude of L before it is considered 0.0 LSMALL = 0.5 * Constants.DEG2RAD2 rdict = {} rdict["T'"] = T0.copy() rdict["L'"] = L0.copy() rdict["S'"] = S0.copy() rdict["rT'"] = T0.copy() rdict["L1_eigen_val"] = 0.0 rdict["L2_eigen_val"] = 0.0 rdict["L3_eigen_val"] = 0.0 rdict["L1_rmsd"] = 0.0 rdict["L2_rmsd"] = 0.0 rdict["L3_rmsd"] = 0.0 rdict["L1_eigen_vec"] = numpy.zeros(3, float) rdict["L2_eigen_vec"] = numpy.zeros(3, float) rdict["L3_eigen_vec"] = numpy.zeros(3, float) rdict["RHO"] = numpy.zeros(3, float) rdict["COR"] = origin rdict["L1_rho"] = numpy.zeros(3, float) rdict["L2_rho"] = numpy.zeros(3, float) rdict["L3_rho"] = numpy.zeros(3, float) rdict["L1_pitch"] = 0.0 rdict["L2_pitch"] = 0.0 rdict["L3_pitch"] = 0.0 rdict["Tr1_eigen_val"] = 0.0 rdict["Tr2_eigen_val"] = 0.0 rdict["Tr3_eigen_val"] = 0.0 rdict["Tr1_rmsd"] = 0.0 rdict["Tr2_rmsd"] = 0.0 rdict["Tr3_rmsd"] = 0.0 ## set the L tensor eigenvalues and eigenvectors (L_evals, RL) = numpy.linalg.eigenvectors(L0) L1, L2, L3 = L_evals good_L_eigens = [] if numpy.allclose(L1, 0.0) or type(L1)==complex: L1 = 0.0 else: good_L_eigens.append(0) if numpy.allclose(L2, 0.0) or type(L2)==complex: L2 = 0.0 else: good_L_eigens.append(1) if numpy.allclose(L3, 0.0) or type(L3)==complex: L3 = 0.0 else: good_L_eigens.append(2) ## no good L eigen values if len(good_L_eigens)==0: return rdict ## one good eigen value -- reconstruct RL about it elif len(good_L_eigens)==1: i = good_L_eigens[0] evec = RL[i] RZt = numpy.transpose(AtomMath.rmatrixz(evec)) xevec = numpy.matrixmultiply(RZt, numpy.array([1.0, 0.0, 0.0], float)) yevec = numpy.matrixmultiply(RZt, numpy.array([0.0, 1.0, 0.0], float)) if i==0: RL[1] = xevec RL[2] = yevec elif i==1: RL[0] = xevec RL[2] = yevec elif i==2: RL[0] = xevec RL[1] = yevec ## two good eigen values -- reconstruct RL about them elif len(good_L_eigens)==2: i = good_L_eigens[0] j = good_L_eigens[1] xevec = AtomMath.normalize(numpy.cross(RL[i], RL[j])) for k in range(3): if k==i: continue if k==j: continue RL[k] = xevec break rdict["L1_eigen_val"] = L1 rdict["L2_eigen_val"] = L2 rdict["L3_eigen_val"] = L3 rdict["L1_rmsd"] = calc_rmsd(L1) rdict["L2_rmsd"] = calc_rmsd(L2) rdict["L3_rmsd"] = calc_rmsd(L3) rdict["L1_eigen_vec"] = RL[0].copy() rdict["L2_eigen_vec"] = RL[1].copy() rdict["L3_eigen_vec"] = RL[2].copy() ## begin tensor transformations which depend upon ## the eigenvectors of L0 being well-determined ## make sure RLt is right-handed if numpy.allclose(numpy.linalg.determinant(RL), -1.0): I = numpy.identity(3, float) I[0,0] = -1.0 RL = numpy.matrixmultiply(I, RL) if not numpy.allclose(numpy.linalg.determinant(RL), 1.0): return rdict RLt = numpy.transpose(RL) ## carrot-L tensor (tensor WRT principal axes of L) cL = numpy.matrixmultiply(numpy.matrixmultiply(RL, L0), RLt) rdict["L^"] = cL.copy() ## carrot-T tensor (T tensor WRT principal axes of L) cT = numpy.matrixmultiply(numpy.matrixmultiply(RL, T0), RLt) rdict["T^"] = cT.copy() ## carrot-S tensor (S tensor WRT principal axes of L) cS = numpy.matrixmultiply(numpy.matrixmultiply(RL, S0), RLt) rdict["S^"] = cS.copy() ## ^rho: the origin-shift vector in the coordinate system of L L23 = L2 + L3 L13 = L1 + L3 L12 = L1 + L2 ## shift for L1 if not numpy.allclose(L1, 0.0) and abs(L23)>LSMALL: crho1 = (cS[1,2] - cS[2,1]) / L23 else: crho1 = 0.0 if not numpy.allclose(L2, 0.0) and abs(L13)>LSMALL: crho2 = (cS[2,0] - cS[0,2]) / L13 else: crho2 = 0.0 if not numpy.allclose(L3, 0.0) and abs(L12)>LSMALL: crho3 = (cS[0,1] - cS[1,0]) / L12 else: crho3 = 0.0 crho = numpy.array([crho1, crho2, crho3], float) rdict["RHO^"] = crho.copy() ## rho: the origin-shift vector in orthogonal coordinates rho = numpy.matrixmultiply(RLt, crho) rdict["RHO"] = rho rdict["COR"] = origin + rho ## set up the origin shift matrix PRHO WRT orthogonal axes PRHO = numpy.array([ [ 0.0, rho[2], -rho[1]], [-rho[2], 0.0, rho[0]], [ rho[1], -rho[0], 0.0] ], float) ## set up the origin shift matrix cPRHO WRT libration axes cPRHO = numpy.array([ [ 0.0, crho[2], -crho[1]], [-crho[2], 0.0, crho[0]], [ crho[1], -crho[0], 0.0] ], float) ## calculate tranpose of cPRHO, ans cS cSt = numpy.transpose(cS) cPRHOt = numpy.transpose(cPRHO) rdict["L'^"] = cL.copy() ## calculate S'^ = S^ + L^*pRHOt cSp = cS + numpy.matrixmultiply(cL, cPRHOt) rdict["S'^"] = cSp.copy() ## calculate T'^ = cT + cPRHO*S^ + cSt*cPRHOt + cPRHO*cL*cPRHOt * cTp = cT + numpy.matrixmultiply(cPRHO, cS) + numpy.matrixmultiply(cSt, cPRHOt) +\ numpy.matrixmultiply(numpy.matrixmultiply(cPRHO, cL), cPRHOt) rdict["T'^"] = cTp.copy() ## transpose of PRHO and S PRHOt = numpy.transpose(PRHO) St = numpy.transpose(S0) ## calculate S' = S + L*PRHOt Sp = S0 + numpy.matrixmultiply(L0, PRHOt) rdict["S'"] = Sp ## calculate T' = T + PRHO*S + St*PRHOT + PRHO*L*PRHOt Tp = T0 + numpy.matrixmultiply(PRHO, S0) + numpy.matrixmultiply(St, PRHOt) +\ numpy.matrixmultiply(numpy.matrixmultiply(PRHO, L0), PRHOt) rdict["T'"] = Tp ## now calculate the TLS motion description using 3 non ## intersecting screw axes, with one ## libration axis 1 shift in the L coordinate system if abs(L1)>LSMALL: cL1rho = numpy.array([0.0, -cSp[0,2]/L1, cSp[0,1]/L1], float) else: cL1rho = numpy.zeros(3, float) ## libration axis 2 shift in the L coordinate system if abs(L2)>LSMALL: cL2rho = numpy.array([cSp[1,2]/L2, 0.0, -cSp[1,0]/L2], float) else: cL2rho = numpy.zeros(3, float) ## libration axis 2 shift in the L coordinate system if abs(L3)>LSMALL: cL3rho = numpy.array([-cSp[2,1]/L3, cSp[2,0]/L3, 0.0], float) else: cL3rho = numpy.zeros(3, float) ## libration axes shifts in the origional orthogonal ## coordinate system rdict["L1_rho"] = numpy.matrixmultiply(RLt, cL1rho) rdict["L2_rho"] = numpy.matrixmultiply(RLt, cL2rho) rdict["L3_rho"] = numpy.matrixmultiply(RLt, cL3rho) ## calculate screw pitches (A*R / R*R) = (A/R) if abs(L1)>LSMALL: rdict["L1_pitch"] = cS[0,0]/L1 else: rdict["L1_pitch"] = 0.0 if L2>LSMALL: rdict["L2_pitch"] = cS[1,1]/L2 else: rdict["L2_pitch"] = 0.0 if L3>LSMALL: rdict["L3_pitch"] = cS[2,2]/L3 else: rdict["L3_pitch"] = 0.0 ## now calculate the reduction in T for the screw rotation axes cTred = cT.copy() for i in (0, 1, 2): for k in (0, 1, 2): if i==k: continue if abs(cL[k,k])>LSMALL: cTred[i,i] -= (cS[k,i]**2) / cL[k,k] for i in (0, 1, 2): for j in (0, 1, 2): for k in (0, 1, 2): if j==i: continue if abs(cL[k,k])>LSMALL: cTred[i,j] -= (cS[k,i]*cS[k,j]) / cL[k,k] ## rotate the newly calculated reduced-T tensor from the carrot ## coordinate system (coordinate system of L) back to the structure ## coordinate system Tr = numpy.matrixmultiply(numpy.matrixmultiply(RLt, cTred), RL) rdict["rT'"] = Tr Tr1, Tr2, Tr3 = numpy.linalg.eigenvalues(Tr) if numpy.allclose(Tr1, 0.0) or type(Tr1)==complex: Tr1 = 0.0 if numpy.allclose(Tr2, 0.0) or type(Tr2)==complex: Tr2 = 0.0 if numpy.allclose(Tr3, 0.0) or type(Tr3)==complex: Tr3 = 0.0 rdict["Tr1_eigen_val"] = Tr1 rdict["Tr2_eigen_val"] = Tr2 rdict["Tr3_eigen_val"] = Tr3 rdict["Tr1_rmsd"] = calc_rmsd(Tr1) rdict["Tr2_rmsd"] = calc_rmsd(Tr2) rdict["Tr3_rmsd"] = calc_rmsd(Tr3) return rdict |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.