Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
restrepo
GitHub Repository: restrepo/ComputationalMethods
Path: blob/master/exams/Examen_2018_2_0_5chiral.ipynb
934 views
Kernel: Python 3

Open In Colab

import pandas as pd import numpy as np import sympy as sy
st=pd.read_csv('https://docs.google.com/spreadsheets/d/e/2PACX-1vQ6ltUxH161xsPuP_-66A86omeh9xce1JFD0Ok2mhO_JdwrPI4bMwlJPWgpxKsS6-doAS-0nhmLshJg/pub?output=csv')

Convert to sympy objects

for x in ['x1','x2','x3','x4','x5']: st[x]=st[x].map(sy.sympify)

Find solutions with two repeated charges

xs=['x1','x2','x3','x4','x5'] st2=pd.DataFrame() for x in xs: for y in xs: if x!=y: st['pair']=x+'='+y tmp=st[ st[x]==st[y] ].reset_index(drop=True) tmp['nu']=tmp[x] st2=st2.append(tmp).reset_index(drop=True) st2=st2.drop_duplicates(xs).reset_index(drop=True)
st2[:3]
st2['nuk']=2-st2['nu'] st2
st22=pd.DataFrame() for x in xs: st2
st2eq=pd.DataFrame() for x in ['x1','x2','x3','x4','x5']: for y in ['x1','x2','x3','x4','x5']: if x!=y: st2['equal']=x+'='+y st2eq=st2eq.append(st2[ st2[x]==st2[y] ]).reset_index(drop=True)
st2eq.drop_duplicates(['x1','x2','x3','x4','x5'])

Keep as strings

st['sltn']=(st.x1+','+st.x2+','+st.x3+','+st.x4+','+st.x5).str.split(',') st['sltnstr']=('('+st.x1+')'+'+'+'('+st.x2+')'+'+'+'('+st.x3+')'+'+'+ '('+st.x4+')'+'+'+'('+st.x5+')')

Solutions with at least two repeated chiral fields

st2=st[st.sltnstr.str.contains( r'(\([\-0-9]*\/*[0-9]+\)).*\1' )].reset_index(drop=True) st2
/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py:1: UserWarning: This pattern has match groups. To actually get the groups, use str.extract. """Entry point for launching an IPython kernel.
st[st.sltnstr.str.contains('\(-13\)')]
sy.simplify('10/3+10/3-6-10/3 ')
st2

Solutions with 4 or 3 chiral fields

def dupli(x,a): isainx=False if a in x: isainx=True return isainx
st0=st[st.sltn.apply(lambda x: dupli(x,'0'))]
st[st.sltnstr.str.contains('13/5')]
st0[~st0.sltnstr.str.contains('0,0')]
st[st.sltnstr.str.contains('13/5')]
st2
st2[st2.sltnstr.str.contains(r'([0-9]*\/*[0-9]+),\1,\1')].reset_index(drop=True)
/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py:1: UserWarning: This pattern has match groups. To actually get the groups, use str.extract. """Entry point for launching an IPython kernel.
st2[~st2.sltnstr.str.contains(r'([0-9]*\/*[0-9]+),\1,\1')].reset_index(drop=True)
/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py:1: UserWarning: This pattern has match groups. To actually get the groups, use str.extract. """Entry point for launching an IPython kernel.