Is there way to customize col_max value without change python-click source code? - python-click

I'm facing a very concrete problem with python-click 8.1.3. The helptext created by Click wastes too much column space when an option name is a tad long. Depicted in picture below:
I trace into Click's source code, and pinpoint a hardcoded value in HelpFormatter.write_dl(), the col_max parameter determines first-column max-width, which is 30, and I hope to reduce it to 16.
As a Click-library user, how can I achieve this without modifying Click's source code? Maybe some class inheritance or patching trick?
Thank you in advance.

You can do something like this:
class MyHelpFormatter(click.HelpFormatter):
def write_dl(self, rows, col_max=5, col_spacing=2):
super().write_dl(rows, col_max, col_spacing)
click.Context.formatter_class = MyHelpFormatter
Check this answer for a similar example

Related

Is there a way for modifying molecule in RDkit?

I have a branched molecule just like in the Image (left one).
I want to add COOH at the end of each branch like Image (right one)
Here is the SMILES format of my molecule in a simplified form with 4 branches.
[N:1]([CH2:2][CH2:3][N:4]([CH2:47][CH2:48][CH:49]([NH:50][CH2:51][CH2:52][NH2:53])[O-:55])[CH2:66][CH2:67][CH:68]([NH:69][CH2:70][CH2:71][NH2:72])[O-:74])([CH2:9][CH2:10][CH:11]([NH:12][CH2:13][CH2:14][NH2:15])[O-:17])[CH2:28][CH2:29][CH:30]([NH:31][CH2:32][CH2:33][NH2:34])[O-:36]
I actually have a much bigger molecule but if i can find a way to do it with the simple one, i think i can extend the solution to the bigger one.
Here is a code example
mod_mol = Chem.ReplaceSubstructs(m,
Chem.MolFromSmiles('[NH2:34]'),
Chem.MolFromSmiles('[CH2:99]'),
replaceAll=True)
mod_mol[0]
for example i tried to change NH2 to CH2 but nothing happens.
In general, it is helpful to observe where the error shows a Nonetype. In this case,
rdkit.Chem.rdmolops.ReplaceSubstructs(Mol, NoneType, Mol)
The issue was caused because Chem.MolFromSmiles was provided with a SMARTS string, like this:
`Chem.MolFromSmiles('[NH2:34]')`
The solution is to use a Chem.MolFromSmarts instead, like this:
Chem.MolFromSmarts('[NH2:34]')

Split model Dymola

I'm having a problem when I use the "Split model" option. What I want to do is basically hide these 10 water volumes:.
I select the tanks then I click on button for splitting with these options:
Final result is just what I want:
When I check the entire model to verify if everything is ok, these errors come out:
I've tried several things such as modifying the text part of the splitted model with no positive results, here's the original NOT modified
Can you please explain to me what kind of error it is? How can I resolve it? Thank you.
Edit: I'm using TIL library
Edit after Markus' answer: in the split model is it necessary to declare the type of liquid and change the portArray definition. I copied these lines of code and everything worked!
parameter TILMedia.LiquidTypes.BaseLiquid liquidType = sim.liquidType1
"Liquid type" annotation (Dialog(tab="SIM",group="SIM"),choices(
choice=sim.liquidType1 "Liquid 1 as defined in SIM",
choice=sim.liquidType2 "Liquid 2 as defined in SIM",
choice=sim.liquidType3 "Liquid 3 as defined in SIM"));
replaceable package MediaConfiguration =
TIL.Utilities.MediaConfiguration
constrainedby TIL.Utilities.Internals.PartialMediaConfiguration
"Media and State Type Configuration" annotation (choicesAllMatching, Dialog(
tab="SIM", group="Media Configuration"));
protected
outer TIL.SystemInformationManager sim "System information manager";
and
public
TIL.Connectors.LiquidPort portArray(
final liquidType=liquidType) ;
TIL.Connectors.LiquidPort portArray1(
final liquidType=liquidType) ;
The issue seems to result from the vectorization of the connectors, that seems to get lost when using "split model". A bit difficult without the actual model, but:
Have you tried to modify the last two connect statements in str3000 to:
connect(portArray, colume.portArray[1])
connect(portArray1, colume.portArray[2])
Additionally on the top level of the model, it seems you have connections to vectors of str3000.portArray. Try to remove them as they seem to be wrong, as you have two non-vector ports.
There should be something like connect(str3000.portArray[1], ...) and connect(str3000.portArray1[2], ...), which should likely be changed to connect(str3000.portArray, ...) and connect(str3000.portArray1, ...).

GAMS: retrieve information from solution

GAMS: I think I have a pretty simple question, however I'm stuck and was wondering if someone could help here.
A simplified version of my model looks like this:
set(i,t) ;
parameter price
D;
variable p(i,t)
e(i,t);
equations
Equation1
obj.. C=sum((i,t), p(i,t)*price);
Model file /all/ ;
Solve file minimizing C using MIP ;
Display C.l;
p(i,t) and e(i,t) are related:
Equation1 .. e(i,t)=e=e(i,t-1)+p(i,t)*D
Now I want to retrieve information from the solution: lets say I want to know at what t e(i,t) has a certain value for example --> e(i,t)= x(i) or otherwise formulated e(i,t=TD)=x(i) find TD, where x(i) thus is depending on i. Does anyone know how I can write this in to my GAMs model? To be clear I do not want to change anything about my solution and the model I have runs; I just want to retrieve this information from the solution given.
So far I tried a couple of thing and nothing worked. I think that this must be simple, can anyone help? Thank you!
Try something like this:
set i /i1*i10/
t /t1*t10/;
variable e(i,t);
*some random dummy "solution"
e.l(i,t) = uniformInt(1,10);
set find5(i,t) 'find all combinations of i and t for which e.l=5';
find5(i,t)$(e.l(i,t)=5) = yes;
display e.l,find5;
Hope that helps,
Lutz

Returning the number of results?

I'm looking to return the number of results found in an ajax fashion on Algolia instant search.
A little field saying something like "There are X number of results" and refines as the characters are typed.
I've read you utilise 'nbHits' but i'm unsure of how to go about it.. Being from a design background.
Thanks for help in advance.
The instantsearch.js stats widget shows the number of results and speed of the search. If you don't want to use the widget, I believe you can still use {{nbHits}} inside of your template wherever you want the number to print.
Very easy when you know how, Thanks for pointing me in the right direction Josh.
This works:
search.addWidget(
instantsearch.widgets.stats({
container: '.no-of-results'
})
);

SAPUI5: set Timepicker configuration for 15 min interval

Is is possible to configure the sap.m.TimePicker to display only 15 minute intervals?
At the moment the user can enter any time they like.
It's possible now with version 1.40.+
There was incorrect information in the API documentation and it wasn't possible even on version 1.38
Change it to a DropDownBox with a value range of 00:00, 00:15, 00:30, ... 23:30, 23:45? This makes the limitation to specific intervals clear at a glance, is easy to implement and avoids entry of undesired values altogether.
While #vwegert 's answer is function I think there is a better way where you you still get the look and feel of the TimePicker.
In the source of the control there is a property minutesStep. If you can set this in the xml or js definition I think you could be onto a winner.
In fact there is a setter (yay) setMinutesStep.
oTimer.setMinutesStep(15); should be a winner for you.
Hope that helps,
Nigel