How to get BuildingElementProxys of ifc-files? - python

I have to extract some convection coolers out of an ifc-file. They're saved as BildingElementProxys & are in relation with IfcRelContainedInSpatialStructure.
My approach is to get all the IfcRelContainedInSpatialStructures & search with a for-loop through the RelatedObjects if there are objects which are also an IfcBuildingElementProxy.
But I'm not which excact commands I got to use for the for-loop.
Would be great if someone could help
That's what I've got so far:
import ifcopenshell
import ifcopenshell.util
from ifcopenshell.util.selector import Selector
import ifcopenshell.file
ifc = ifcopenshell.open(...)
selector = Selector()
buildingelementproxies = selector.parse(ifc, ".IfcBuildingElementProxy")
spaces = selector.parse(ifc, ".IfcSpace")
containedrelation = selector.parse(ifc, ".IfcRelContainedInSpatialStructure")
print (containedrelation)

Related

How to add a Chain, Residues and atoms in pdb file?

I want to add a chain with all the residues and one carbon-alpha atom per residue using the OpenMM. Here the link of instances can be used openMM documentation . Currently I have one chain in my pdb file pdb file. Here is what I've tried:
from simtk.openmm.app import *
from simtk.openmm import *
from simtk.unit import *
import numpy as np
import mdtraj as md
# Here I remove all other atoms except carbon-alpha and stored them in a new file 'CA_only.pdb'
main_pdb = md.load_pdb('1PGB.pdb')
atoms_to_keep = [atom.index for atom in main_pdb.topology.atoms if atom.name == 'CA']
new_pdb = main_pdb.atom_slice(atoms_to_keep)
new_pdb.save('CA_only.pdb')
# Then I try to add a chain and residue, but no results
pdb = PDBFile('CA_only.pdb')
top = topology.Topology
chain=top.addChain(id='A')
residue = top.addResidue(MET, 0)
I might be using wrong names of residues. But I don't know what is wrong. Could someone have any idea how to resolve this? Thanks!!

What is the invalid syntax error in this def?

I am trying to use this Anki add-on written in python.
However, on Anki 2.1 startup, an error is returned.
May anyone have a quick look at the short code in the link and spot the error? Maybe it is incompatible with a recent update of python?
# Anki 2.0 addon
# Author EJS
# https://eshapard.github.io/
#
# Sets the learning steps sequence of each deck options group.
from anki.hooks import addHook
from aqt import mw
#from aqt.utils import showInfo
#import time
ignoreList = ['Default', 'OnHold', 'Parent Category'] #Deck options groups to ignore
# run this on profile load
def updateLearningSteps():
#find all deck option groups
dconf = mw.col.decks.dconf
#cycle through them one by one
for k in dconf:
if dconf[k]["name"] not in ignoreList:
#showInfo(dconf[k]["name"])
ease = dconf[k]["new"]["initialFactor"]/1000.0
#create learning steps
tempList = [15]
for i in range(10):
l = int(1440*ease**i)
if l < 28800:
tempList.append(l)
else:
gradInts = [(l/1440),(l/1440)]
break
#showInfo(str(tempList))
#showInfo(str(gradInts))
mw.col.decks.dconf[k]["new"]["delays"] = tempList
mw.col.decks.dconf[k]["new"]["ints"] = gradInts
mw.col.decks.save(mw.col.decks.dconf[k])
mw.res
et()
# add hook to 'profileLoaded'
addHook("profileLoaded", updateLearningSteps)
This is the error: https://user-images.githubusercontent.com/52420923/66923073-ba2df980-f017-11e9-8b66-c8799db29850.png
The code you've posted doesn't match the error. The error has def updateLearningSteps() without a colon at the end of the line. That is indeed a syntax error.

Selenium - Can't get text from element (Python)

I'm trying to get the result of an input from:
https://web2.0calc.com/
But I can't get the result. I've tried:
result = browser.find_element_by_id("input")
result.text
result.get_attribute("textContent")
result.get_attribute("innerHtml")
result.get_attribute("textContent")
But it doesn't work and returns an empty string...
The required element is a Base64 image, so you can either get a Base64 value from #src, convert it to an image and get a value with a tool like PIL (quite complicated approach) or you can get a result with a direct API call:
import requests
url = 'https://web2.0calc.com/calc'
data = data={'in[]': '45*23'} # Pass your expression as a value
response = requests.post(url, data=data).json()
print(response['results'][0]['out'])
# 1035
If you need the value of #input:
print(browser.find_element_by_id('input').get_attribute('value'))
My preference would be for the POST example (+ for that) given but you can grab the expression and evaluate that using asteval. There may be limitations on asteval. It is safer than eval.
from selenium import webdriver
from asteval import Interpreter
d = webdriver.Chrome()
url = 'https://web2.0calc.com/'
d.get(url)
d.maximize_window()
d.find_element_by_css_selector('[name=cookies]').click()
d.find_element_by_id('input').send_keys(5)
d.find_element_by_id('BtnPlus').click()
d.find_element_by_id('input').send_keys(50)
d.find_element_by_id('BtnCalc').click()
expression = ''
while len(expression) == 0:
expression = d.find_element_by_id('result').get_attribute('title')
aeval = Interpreter()
print(aeval(expression))
d.quit()

Extract and plot XML data using python

I'm trying to analyze my XML file, I would like to get data X Y Z for advanced analysis later and then plot all values.
Here the XML files looks like:
<UserPosition>
<X>-12.2934008394709</X>
<Y>52.488259963403273</Y>
<Z>-0.92276278637695341</Z>
</UserPosition>
this is my code :
from lxml import etree
import matplotlib.pyplot as plt
import numpy as np
# Read xml files
PostX = []
PostY= []
Thikness = []
tree = etree.parse("XMLFILE.xml")
for UserPosition in
tree.xpath("/cResult/measure/lMeasuredItem/cMeasureItem/UserPosition/X"):
PostX.append(UserPosition.text)
print PostX
I'm getting this ! :
['-12.2934008394709', '-9.1133008238197366', '-5.9329608027622784', '-2.7523007917339029',
Any help to get a proper values for analysis.
Is there any reason you cant change
PostX.append(UserPosition.text)
to
PostX.append(float(UserPosition.text))
Otherwise, it would be helpful to see how it is all your x, y and z values (or certainly more of them) are structured in this .xml file.

I want to extract the MAC address of the following python-wifi 0.6.1 code

The following code tries to extract the MAC address of all nearby APs and then saves them in a matrix, i dont know what is wrong. it uses the library python-wifi 0.6.1. Here is the code and error:
`
import errno
import sys
import types
import pythonwifi.flags
from pythonwifi.iwlibs import Wireless, WirelessInfo, Iwrange, getNICnames, getWNICnames
i=0
ArregloMAC=[20][30]
wifi= Wireless('wlan0')
results = wifi.scan()
(num_channels, frequencies) = wifi.getChannelInfo()
print "%-8.16s Scan completed :" % (wifi.ifname, )
for ap in results:
index = 1
ArregloMAC[i][index-1]= str("%d-%s" % (_, ap.bssid))
index = index+1
print ArregloMAC`
IndexError: list index out of range
This line
ArregloMAC=[20][30]
will give you an index out of range straight off. What it says is, create a list of one element, [20], then take the 31st element of that list, and assign it to ArregloMAC. Since the list has only one element you will inevitably get an error.
It looks like you are trying to declare a 2-dimensional array. That is not how Python lists work.

Categories

Resources